Phrogz
11/24/2007 2:34:00 PM
On Nov 24, 4:35 am, MonkeeSage <MonkeeS...@gmail.com> wrote:
> On Nov 24, 1:25 am, Aaron Patterson <aa...@tenderlovemaking.com>
> 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.