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) over 2 years ago. Updated about 2 years ago.

Status:
Closed
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

Also available in: Atom PDF

Like0
Like0Like0Like0