From: Eric Hodel Date: 2006-12-11T04:52:33+09:00 Subject: Re: defining key equivalence in a hash On Dec 10, 2006, at 11:33 , Suraj Kurapati wrote: > Hello, > > I'm trying to make two keys equivalent by having their #hash method > produce the same result. But this does not seem to work: > > irb(main):001:0> class K; def hash; 90; end; end > => nil > irb(main):002:0> h = {} > => {} > irb(main):003:0> h[K.new] = 1 > => 1 > irb(main):004:0> h.key? K.new # <---- I want this to return true! > => false > > What am I missing? class K; def eql?(other) true; end; end #eql? is called if o1.hash == o2.hash. If #eql? returns true the objects belong to the same index. -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!