Bug #10353
Updated by nobu (Nobuyoshi Nakada) over 10 years ago
Earlier this week I cross by a weird bug using a gem and after digging into the problem I found this issue with MRI. I could not reproduce it on 1.9.3-p545 nor on the 2.2.0-preview1, the issue occurs on the 2.1.2 ~~~ 2.1.2 :001 > class Foo 2.1.2 :002?> def bar(msg) 2.1.2 :003?> puts msg 2.1.2 :004?> end 2.1.2 :005?> end => :bar 2.1.2 :006 > foo = Foo.new => #<Foo:0x007f9e1410e780> 2.1.2 :007 > foo.instance_eval("def bar2(*args, &block) bar(*args, &block) end") => :bar2 2.1.2 :008 > foo.respond_to?(:bar2) => true 2.1.2 :009 > foo.bar2 ArgumentError: wrong number of arguments (0 for 1) from (irb):2:in `bar' from (eval):1:in `bar2' from (irb):9 from /Users/dyego/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>' 2.1.2 :010 > foo.bar2('bar') bar => nil 2.1.2 :011 > foo.bar2 => nil 2.1.2 :012 > foo.bar2 => nil ~~~ It behaves as expected on the 1.9.3 as it does on the 2.2.0-preview1 ~~~ 1.9.3-p545 :001 > class Foo 1.9.3-p545 :002?> def bar(msg) 1.9.3-p545 :003?> puts msg 1.9.3-p545 :004?> end 1.9.3-p545 :005?> end => nil 1.9.3-p545 :006 > foo = Foo.new => #<Foo:0x007fb114043130> 1.9.3-p545 :007 > foo.instance_eval("def bar2(*args, &block) bar(*args, &block) end") => nil 1.9.3-p545 :008 > foo.respond_to?(:bar2) => true 1.9.3-p545 :009 > foo.bar2 ArgumentError: wrong number of arguments (0 for 1) from (irb):2:in `bar' from (eval):1:in `bar2' from (irb):9 from /Users/dyego/.rvm/rubies/ruby-1.9.3-p545/bin/irb:12:in `<main>' 1.9.3-p545 :010 > foo.bar2('bar') bar => nil 1.9.3-p545 :011 > foo.bar2 ArgumentError: wrong number of arguments (0 for 1) from (irb):2:in `bar' from (eval):1:in `bar2' from (irb):11 from /Users/dyego/.rvm/rubies/ruby-1.9.3-p545/bin/irb:12:in `<main>' ~~~