From: "David A. Black" Date: 2004-12-09T04:44:17+09:00 Subject: Re: Idiom for creating hash from two arrays Hi -- On Thu, 9 Dec 2004, Glenn Parker wrote: > David A. Black wrote: >> On Thu, 9 Dec 2004, Glenn Parker wrote: >>> This style of expression can only create a new hash instead of updating an >>> existing hash. I think the "core" operation is updating/merging an >>> existing hash with a set of matched keys and values. >> >> hash.update(key_array.hash_with(value_array)) :-) > > Unless Ruby is much smarter than I thought, this will build a new (albeit > temporary) hash, then pass it to Hash#update. Not quite the same as updating > hash in place, and less efficient in terms of memory usage. > > The smiley suggests to me you already appreciate this distinction. :) Not exactly... more that I don't think updating an existing hash from two arrays really needs its own semantics, beyond those provided by Hash#update. I think the most common uses of Hash#update involve hashes that already exist. So, for example, you might have: hash.update(Hash[*some_array.flatten]) which also probably isn't the most efficient possible way, but I'd rather keep the question of optimizing Hash#update separate from the question of creating hashes out of two arrays. David -- David A. Black dblack@wobblini.net