Hello --

On Sun, 21 Oct 2001, Daniel Berger wrote:

> Hi all,
>
> What's the easiest (i.e. a one liner) for creating a hash based on an array?
> I just wanted to convert an array to a hash, using the even numbered indices
> as the key and the odd numbered indices as the value for that key.
>
> array = ['one', 1, 'two', 2, 'three', 3]

hash = Hash[*array]

(The * turns the array into a bare list of its elements.)

I've always advocated an Array#to_h method, though that was before I got the
hang of the above :-)  I still think there might be use for some methods that
make array<->hash conversions more transparent.


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav