From: Charles Mills Date: 2004-08-06T11:34:53+09:00 Subject: Re: Sets are not extensional On Aug 5, 2004, at 6:41 PM, George Ogata wrote: > Kristof Bastiaensen writes: > >> {}.hash == {}.hash >> => false >> Set[].hash == Set[].hash >> => false >> [].hash == [].hash >> => true >> >> I have no idea for the reason why different hashes have different >> hashvalues, while different arrays may get the same value (based on >> the >> contents of the array). > > This seems like a blatant bug to me. `a.eql? b' must imply `a.hash == > b.hash', yet: I agree: > a = {} #=> {} > a.hash #=> 1650134 > a.id #=> 1650134 > b = {} #=> {} > b.hash #=> 1639814 # So hash on an empty hash returns the objects id.... > a = {"a"=>"b"} #=> {"a"=>"b"} > a.hash #=> 1682094 > a.clear #=> {} > a.hash #=> 1682094 # Looks like no two hashes hash to one another... # Here is the reason /* in object.c */ rb_mKernel = rb_define_module("Kernel"); rb_include_module(rb_cObject, rb_mKernel); /* ..snip.. */ rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0); /* in hash.c the "hash" method is never overridden. So rb_obj_id() is the "hash" method for hashes. */ -Charlie