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.
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.