From: Robert Dober Date: 2009-07-23T01:56:10+09:00 Subject: Re: Incorrect -0.0.hash - Ruby bug. On 7/22/09, John W Higgins wrote: > Morning Thomas, > > > On Wed, Jul 22, 2009 at 9:24 AM, Thomas B. wrote: > > > Hello. I just found a bug in Ruby, version 1.9.1p0, Windows. > > > > In the rdoc to Object#hash we read > > (http://ruby-doc.org/core/classes/Object.html#M000337): > > > > "This function must have the property that a.eql?(b) implies a.hash == > > b.hash." > > My understanding is that this relationship shall be kept for the purpose of correct hash key behavior 553/60 > ruby -v -e 'p( {0.0 => 42}[-0.0] )' ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux] nil which is not nice. That said floats as hash keys are a bad idea of course because of equality is not very well defined anyway. Cheers Robert > > > Actually Float overrides both #eql? and #hash so the contract is not > applicable inside that class. Is that the best option in the world?? - > probably not - but that would make it a non bug in theory. > > > John > -- Toutes les grandes personnes ont d’abord été des enfants, mais peu d’entre elles s’en souviennent. All adults have been children first, but not many remember. [Antoine de Saint-Exupéry]