From: Robert Dober Date: 2007-03-03T04:09:59+09:00 Subject: Re: Hash keys don't work as expected On 3/2/07, Robert Klemme wrote: > On 02.03.2007 19:28, Tim Hunter wrote: > > DK wrote: > >> On Mar 2, 12:58 pm, Tim Hunter wrote: > >>>> => {[1, 2, 3]=>"test"} > >>>> DK > >>> Posted viahttp://www.ruby-forum.com/. > >> Ah, thank you. Why is this necessary? Isn't the lookup just a matter > >> of matching object_id's? > > > > Remember that hash values are distributed into buckets based on their > > key. Change the key, change the bucket. > > More precisely if the hash of the key changes the bucket changes. And > since Array calculates it's hash based on the content changing the > content means changing the key. And, to the OP, lookups in Hashes are > not done via #object_id but via #hash: > http://en.wikipedia.org/wiki/Hashtable which all is necessary in order to have mutable keys, I guess that it is very difficult to think about that in the beginning when not yet used to it. BTW. I try to avoid to mutate hash keys, I know my limits ;) Cheers Robert > > Kind regards > > robert > > -- We have not succeeded in answering all of our questions. In fact, in some ways, we are more confused than ever. But we feel we are confused on a higher level and about more important things. -Anonymous