From: ara.t.howard@... Date: 2006-12-11T04:54:37+09:00 Subject: Re: defining key equivalence in a hash On Mon, 11 Dec 2006, 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? K#eql? for example harp:~ > cat a.rb class K attr 'key' def initialize() @key = 42 end def hash() @key.hash end def eql?(other) other.key == @key end end p K.new => 'which', K.new => 'one' harp:~ > ruby a.rb {#=>"one"} regards. -a -- if you want others to be happy, practice compassion. if you want to be happy, practice compassion. -- the dalai lama