Project

General

Profile

Actions

Bug #18389

closed

`binding.irb` can fail in some classes that implement `context` and `print` methods.

Added by ioquatix (Samuel Williams) about 2 months ago. Updated 1 day ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:106495]

Description

class Foo
  def boop
    binding.irb
  end

  def context
  end

  def print
  end
end

Foo.new.boop

It fails with:

> ruby ./test.rb

From: ./test.rb @ line 3 :

    1: class Foo
    2:   def boop
 => 3:     binding.irb
    4:   end
    5:   
    6:  def context
    7:  end
    8:  

./test.rb:9:in `print': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from /Users/samuel/.gem/ruby/3.0.3/gems/irb-1.3.7/lib/irb/extend-command.rb:238:in `install_alias_method'
    from /Users/samuel/.gem/ruby/3.0.3/gems/irb-1.3.7/lib/irb/extend-command.rb:252:in `block in extend_object'
    from /Users/samuel/.gem/ruby/3.0.3/gems/irb-1.3.7/lib/irb/extend-command.rb:251:in `each'
    from /Users/samuel/.gem/ruby/3.0.3/gems/irb-1.3.7/lib/irb/extend-command.rb:251:in `extend_object'
    from /Users/samuel/.gem/ruby/3.0.3/gems/irb-1.3.7/lib/irb.rb:466:in `extend'
    from /Users/samuel/.gem/ruby/3.0.3/gems/irb-1.3.7/lib/irb.rb:466:in `initialize'
    from /Users/samuel/.gem/ruby/3.0.3/gems/irb-1.3.7/lib/irb.rb:959:in `new'
    from /Users/samuel/.gem/ruby/3.0.3/gems/irb-1.3.7/lib/irb.rb:959:in `irb'
    from <internal:prelude>:5:in `irb'
    from ./test.rb:3:in `boop'
    from ./test.rb:13:in `<main>'

I suggest that binding.irb should be a little bit less invasive to avoid these kinds of issues.

Actions #1

Updated by ioquatix (Samuel Williams) about 2 months ago

  • Description updated (diff)

Updated by jeremyevans0 (Jeremy Evans) 21 days ago

I've submitted a pull request to fix this error: https://github.com/ruby/irb/pull/325

Actions #3

Updated by osyo (manga osyo) 1 day ago

  • Status changed from Open to Closed

Applied in changeset git|b6b2e489f10bfc771beae8fa0ee5237613acd18f.


[ruby/irb] Changed to call Kernel.print

If you call binding.irb on a class defined #print, it will crash, so call Kernel.print.

Fix [Bug #18389] binding.irb can fail in some classes that implement context and print methods.

https://github.com/ruby/irb/commit/d54b271984

Actions

Also available in: Atom PDF