From: Christoph Date: 2004-12-04T22:51:36+09:00 Subject: Re: Hash#eql? and Hash key testing Joel VanderWerf schrieb: > > The ri docs for Object#eql? say: > > The +eql?+ method returns +true+ if _obj_ and _anObject_ have the > same value. Used by +Hash+ to test members for equality. > > However, the second sentence doesn't seem to be consistent with the > behavior of Hash (and Set): > > h1 = {1=>2, 3=>4} > h2 = {1=>2, 3=>4} > > p h1.eql?(h2) # ==> true > > h={h1=>true} > > p h[h1] # ==> true > p h[h2] # ==> nil > > Based on the docs, I would have expected > > p h[h2] # ==> true > > Have I misunderstood? > No you have not, however hashes have different Hash values (their ids - the same is true for Sets) so all bets are off ---- class A def ==(rhs) true end alias :eql? :== end def test a,b = A.new,A.new ah = {a => true } bh = {b => true } p ah[b] end test # nil class A def hash 1 end end test # true class A remove_method :eql? end test # nil --- /Christoph