From: Jim Moy Date: 2003-12-16T10:29:39+09:00 Subject: Re: [Nuby] Object ID Lookup? >> a = { "a" => 1, "b" => 2 } >> b = { "c" => 4, "d" => 3 } >> arr = [a, b] >> ids = arr.collect {|h| h.id} >> lookup = {} >> arr.each { |h| lookup[h.id] = h } >> cmp = ids.collect {|id| lookup[id]} >> ids == cmp => true >> >> In my instance, I've got a reference set of hashes that I'm >> pointing to from multiple arrays. Those arrays are manipulated >> depending on sorting and other factors. >> >> I don't want to get Hash#== involved so I'm using the Hash >> object id's. After processing is completed, I'd like to get >> back from the IDs to the object references. The lookup is >> working, but I was wondering if there was a better method. > > Eric Hodel (drbrain@segment7.net) wrote: > > Not seeing the internals of your code, will Object#equal? (identical > object ids) be able to replace #==? Yes, the code similar to the above example works as-is with the hash ids, as I wanted to avoid Hash#== and all the comparisons it will perform. Judging by the replies so far, I think I'll keep the lookup hash. Jim