Hi -- On Wed, 8 Dec 2004, Glenn Parker wrote: > David A. Black wrote: >> On Wed, 8 Dec 2004, Glenn Parker wrote: >>> Why does it need a new name? Instead, why not extend Hash.new to do this >>> when it is passed two arrays? It seems pretty natural to me, and I don't >>> see any conflict with existing usage. >> >> What if you wanted to set a default value for the hash? > > Hash.new is already varadic: > > Hash.new => hash > Hash.new(obj) => aHash > Hash.new {|hash, key| block } => aHash > > The second form specifies a default value. The third form specifies a block > to generate missing values. I was suggesting that we add one more form: > > Hash.new(keyArray, valueArray) => aHash > > This form is easily distinguishable from the original three, so you could > still create a hash with a default value using the second or third form. But what about a hash from two arrays with a default value? > However, the more I think about it, the more I see this as a typical > operation on existing hashes, not simply a constructor. So, I would rather > see alternate forms for merge and update: > > Hash#merge(keyArray, valueArray) > Hash#update(keyArray, valueArray) > > Then, to the original problem would be expressed as: > > h = Hash.new.merge(keyArray, valueArray) 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. (I think I submitted an RCR to this effect at some point... but I can't remember its status.) David -- David A. Black dblack / wobblini.net