Issue #7045 has been updated by marcandre (Marc-Andre Lafortune).

Status changed from Open to Closed

> I'm not sure that explains it. The first and third tests pass

Sorry, I didn't focus on the other tests. So the reason the first and third test pass is that Hash lookup uses `hash` and `eql?`, except that if the objects are the same (same object_id), it assumes they are `eql?`. I'm assuming this is for performance reasons, since it should be true for almost all objects. It isn't for NaN, though, so this can give strange results:

    n = 0.0/0
    n.eql?(n) # => false
    h = {n => :nan}
    h[n] # => :nan (exact same object)
    h[0.0/0] # => nil (since another float was constructed)

The first test passes because a hash is built with `obj` as the key, and afterwards lookup succeeds for `obj` as it is the exact same object.
The last test passes for the same reason, because the key and the lookup are done on the exact same array `[obj]`.
The second test fails because the key and the lookup are not the same object (different `object_id`), so `eql?` is called and `[obj].eql? [obj]` returns false.

> and all of them used to pass in 1.8.

In 1.8, `eql?` was not delegated at all. So you had `obj.eql?(obj) # => true`, but on the other hand `SimpleDelegator.new(42).eql?(42) # => false`. 

> This seems like a duplicate of http://bugs.ruby-lang.org/issues/6408. Not sure how to close this, but it can be closed.

Indeed, if 6408 was fixed, we'd have `obj.eql? obj` return true and all your tests would pass. I'll close this then.
----------------------------------------
Bug #7045: DelegateClass array subtraction
https://bugs.ruby-lang.org/issues/7045#change-29693

Author: benmoss (Ben Moss)
Status: Closed
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.0.0dev (2012-09-21) [x86_64-darwin11.4.0]


When I have an array that contains an array that contains a single instance of a class that inherits from DelegateClass, and I subtract from that array another array containing another array containing the same nested object, Ruby does not return an empty array. I've attached a test file that should replicate the one failing scenario, as well as some complimentary scenarios that do work as I had expected.


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