From: Eric Hodel Date: 2006-12-27T04:53:31+09:00 Subject: Re: Hash with two identical keys? 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. > 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 -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!