From: "Florian Groß" Date: 2005-05-05T21:54:10+09:00 Subject: Re: Whats so different about a Hash? Andrew Walrond wrote: > So if a.eql?(b), then a.hash MUST EQUAL b.hash. > > Lets see: > > irb(main):038:0> a={1=>2} > => {1=>2} > irb(main):039:0> b={1=>2} > => {1=>2} > irb(main):040:0> a.eql?(b) > => true > irb(main):041:0> a.hash == b.hash > => false > > So what gives? > > irb(main):034:0> {1=>2}.hash => -605137920 > irb(main):035:0> {1=>2}.hash => -605147880 > irb(main):036:0> {1=>2}.hash => -604944118 Odd, I thought Hash#hash had already been added to Ruby itself recently. I guess you can workaround it like this: class Hash def hash() [self.to_a, self.class].hash end end Though I am not sure if that is the correct semantics. (It could be the case that Hash#eql?() also compares default values.)