From: "David A. Black" Date: 2004-12-09T00:59:36+09:00 Subject: Re: Idiom for creating hash from two arrays Hi -- On Thu, 9 Dec 2004, Glenn Parker wrote: > David A. Black wrote: >> But what about a hash from two arrays with a default value? > > At some point, it becomes more legible to use separate operations: > > h = Hash.new(keys, values) > h.default = "defaultValue" > > Hash#default and Hash#default= are already defined. I know. I'm still not in favor of changing the signature of Hash#new to accomodate this particular case. > Oddly, there is no Hash#default_proc= to complement Hash#default_proc. > >> I'm actually more drawn to some kind of #to_h-ish operation on arrays, >> like: >> >> key_array.hash_with(value_array) >> >> rather similar to Array#zip, but producing a hash. > > 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)) :-) David -- David A. Black dblack@wobblini.net