# Strange behavior when redefining methods on object instances (possible bug)

**URL:** <https://www.ruby-forum.com/t/strange-behavior-when-redefining-methods-on-object-instances-possible-bug/166166>\
**Category:** IronRuby\
**Created:** [April 22, 2009, 2:44pm UTC](https://www.ruby-forum.com/t/strange-behavior-when-redefining-methods-on-object-instances-possible-bug/166166 "2009-04-22T14:44:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![murena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ba0ec/32.png) [@murena](https://www.ruby-forum.com/u/murena)\
**Post date:** [April 22, 2009, 2:44pm UTC](https://www.ruby-forum.com/t/strange-behavior-when-redefining-methods-on-object-instances-possible-bug/166166/1 "2009-04-22T14:44:16Z")

</div>

Hi,  
while in the process of trimming down the failure rate of the  
core/array specs I noticed a strange behavior of IronRuby. I’m pasting  
here two repl sessions I used to reproduce it:

```
>>> foo = Object.new
=> #<Object:0x000005c>
>>> bar = Object.new
=> #<Object:0x000005e>
>>>
>>> def foo.to_s; p "foo#to_s has been invoked"; "foo" end;
=> nil
>>>
>>> foo
"foo#to_s has been invoked"
=> foo
>>> bar
=> #<Object:0x000005e>

```

As you can see there is nothing wrong here, so here is the second  
session where the only difference is in that the order of foo and bar  
at the end of the snippet is inverted:

```
>>> foo = Object.new
=> #<Object:0x000005c>
>>> bar = Object.new
=> #<Object:0x000005e>
>>>
>>> def foo.to_s; p "foo#to_s has been invoked"; "foo" end;
=> nil
>>>
>>> bar
=> #<Object:0x000005e>
>>> foo
=> #<Object:0x000005c>

```

I would expect to get “foo#to\_s has been invoked” printed just like in  
the first snippet (and IRB on MRI behave like expected), but instead  
the method called on foo is the one of Object#to\_s (a step-by-step  
debug session confirmed this). Could it be related to some issues in  
the method caching stuff that happens deep into the internals of  
IronRuby?

This problem affects certain mocking scenarios when running mspec (eg.  
“Array#== returns false if any element is not == to the corresponding  
element in the other the array” and “Array#delete removes elements  
that are #== to object”, but their implementation looks ok to me), so  
it might even be possible that more specs which are being reported as  
failures are not related to bogus implementations, but it is just  
mspec that is failing due to a bug.

Is there anyone that can confirm this before I file a bug on the bug  
tracker?

Thanks,  
Daniele

–  
Daniele A.  
[http://www.clorophilla.net/blog/](http://www.clorophilla.net/blog/)  
[http://twitter.com/JoL1hAHN](http://twitter.com/JoL1hAHN)

---

<div class="post-metadata">

**Author:** ![murena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ba0ec/32.png) [@murena](https://www.ruby-forum.com/u/murena)\
**Post date:** [April 22, 2009, 5:56pm UTC](https://www.ruby-forum.com/t/strange-behavior-when-redefining-methods-on-object-instances-possible-bug/166166/2 "2009-04-22T17:56:26Z")

</div>

Please file a bug.

Thanks,  
Tomas

---

<div class="post-metadata">

**Author:** ![murena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ba0ec/32.png) [@murena](https://www.ruby-forum.com/u/murena)\
**Post date:** [April 23, 2009, 8:31pm UTC](https://www.ruby-forum.com/t/strange-behavior-when-redefining-methods-on-object-instances-possible-bug/166166/3 "2009-04-23T20:31:30Z")

</div>

Bug report filed here:  
[http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=761](http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=761)

Thanks,  
Daniele

On Wed, Apr 22, 2009 at 17:37, Tomas M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Â Â \>\>\> def foo.to\_s; p “foo#to\_s has been invoked”; “foo” end;  
> at the end of the snippet is inverted:  
> Â Â =\> #Object:0x000005e  
> This problem affects certain mocking scenarios when running mspec (eg.  
> Daniele
> 
> * * *
> 
> Ironruby-core mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
Daniele A.  
[http://www.clorophilla.net/blog/](http://www.clorophilla.net/blog/)  
[http://twitter.com/JoL1hAHN](http://twitter.com/JoL1hAHN)
