The Ruby docs read as follows:
The eql? method returns true if obj and other refer to the same hash key.
So in order to use #eql?
to compare two objects (or use objects as Hash keys), the object has to implement #hash
in a meaningful manner.
How come the following happens?
class EqlTest
def hash
123
end
end
a = EqlTest.new
b = EqlTest.new
a.hash == b.hash # => true
a.eql? b # => false
I could of course implement EqlTest#eql?
but shouldn't the implementation inherited from Object
be something along the lines of hash == other.hash
already?
Thanks for your hints!