From: Alex LeDonne Date: 2006-12-27T03:14:48+09:00 Subject: Re: Hash with two identical keys? On 12/26/06, Trans wrote: > >From Facets' multiton.rb (which is primarily Floran Franks' work), I'm > getting somthing that doesn't make any sense: > > POOLS[self] ||= {} > p POOLS[self].class > p POOLS[self].keys > > Is outputing: > > Hash > [[{:strip_comments=>false}], [{:strip_comments=>false}]] > > How can two identical keys be in a hash? > > T. > irb(main):005:0> bob = [{:whee => false}] => [{:whee=>false}] irb(main):006:0> bob.hash => 23244868 irb(main):007:0> roger = [{:whee => false}] => [{:whee=>false}] irb(main):008:0> roger.hash => 23235888 irb(main):009:0> bob.eql? roger => false irb(main):010:0> bob[0].eql? roger[0] => false irb(main):011:0> bob[0].hash => 23244870 irb(main):012:0> roger[0].hash => 23235890 I think it boils down to: there is no Hash#hash which inspects the contents - Hash inherits Object#hash which is Object#object_id, and the two hashes, while they appear to have the same contents, are not the same object. So the keys are not "identical". -A