[#65451] [ruby-trunk - Feature #10333] [PATCH 3/1] optimize: "yoda literal" == string — ko1@...

Issue #10333 has been updated by Koichi Sasada.

9 messages 2014/10/07

[ruby-core:65577] [ruby-trunk - Bug #10353] [Open] weird behavior when dynamically adding method using instance_eval

From: dyego@...
Date: 2014-10-10 02:58:15 UTC
List: ruby-core #65577
Issue #10353 has been reported by Dyego Costa.

----------------------------------------
Bug #10353: weird behavior when dynamically adding method using instance_eval 
https://bugs.ruby-lang.org/issues/10353

* Author: Dyego Costa
* Status: Open
* Priority: Normal
* Assignee: 
* Category: core
* Target version: 
* ruby -v: 2.1.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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>'



-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next