From: Phrogz Date: 2007-11-24T23:35:05+09:00 Subject: Re: Hashes, Sets, and eql? On Nov 24, 4:35 am, MonkeeSage wrote: > On Nov 24, 1:25 am, Aaron Patterson > wrote: > > > Nope. I don't want a shallow comparison. I need to use my sets as hash > > keys, so I need .eql? and .hash. Set calls eql? on the internal hash object. > > And eql? implies a.hash == b.hash. That is an object comparison, since > Object#hash gives a unique value for every object like Object#id. What > you need is shallow comparison of values rather than objects: a == b. > I'm not sure how to easily make Hash do that. Not always true: irb(main):001:0> a1 = [:a,1,'foo'] => [:a, 1, "foo"] irb(main):002:0> a2 = [:a,1,'foo'] => [:a, 1, "foo"] irb(main):003:0> a1.hash => 876036089 irb(main):004:0> a2.hash => 876036089 This discussion (using Hashes as hash or set keys, and the requirements and possible implementations of of eql? for this to work as sometimes desired) occurred in the last month or two on this list.