On Wed, 8 Dec 2004, Jonathan Paisley wrote:

> On Wed, 08 Dec 2004 23:25:10 +0900, Glenn Parker wrote:
>
>> 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)
>
> That's a good point. Given that, I don't think it's really necessary to
> make any alterations to the constructors.
>
> I suppose in the example above using merge! or update would be appropriate,
> since the original hash isn't needed.
>
>  h = Hash.new.merge!(keys,values)
>
> In addition, it would be nice if keys and values need not be arrays -
> just Enumerables. Implementing this may be a bit tricky, however.

Very :-)  I wouldn't want to create a hash from one of these:

   class Forever
     include Enumerable
     def each
       i = 1
       loop { yield i += 1 }
     end
   end

Arrays are a useful, and much used, way to "normalize" certain kinds
of enumerable operations and input (like find, map, etc.).  I think
any proto-hashing would be best done array-wise.


David

-- 
David A. Black
dblack / wobblini.net