From: Trans Date: 2006-12-27T05:09:30+09:00 Subject: Re: Hash with two identical keys? Eric Hodel wrote: > On Dec 26, 2006, at 11:22, Trans wrote: > > Trans wrote: > >> thanks Ara and Jon, > >> > >> I see what your saying. I was using #== not #eql? in comparing the > >> keys. So I see why it's faling now. How do I get aorund this? I'm > >> caching object based on therr initialization paramaters, which has to > >> be an array. Is there a simpler way or do I have to do something > >> like: > >> > >> class Parameters < Array > >> alias :eql? :== > >> end > > > > Ugh. Nothing like that works either. It's not using eql? or equal?, > > but > > rather #hash (I guess that's actually what you were trying to say > > Ara). > > A Hash only asks if one object is #eql? to another when they have the > same #hash. You can't use a Hash as a Hash key because Hash#hash is > not implemented that way. I see. So it's not using object_id but a.hash == b.hash && a.eql?(b) Is that right? > > This doen't make any sense to me. Why do identical strings and arrays > > have the same #hash value but not hashes? > > Likely because: > > s = '' > s.hash > > and: > > a = [] > a << a > a.hash > > are easier to compute than: > > h = {} > h[h] = h > h.hash Hmm... the expection gums up the works. T.