From: Servando Garcia Date: 2007-03-20T20:51:05+09:00 Subject: Re: array to hash
Guess I should have googled harder/longer I have found some code that appears to work. Now I'll have to spend sometime stepping through it.
Here is the code:
 
class Array
def to_h(&block)
Hash[*self.collect { |v|
[v, block.call(v)]
}.flatten]
end
end
 
 
and the link to the page:
http://snippets.dzone.com/posts/show/302
 
Harold, Please forgive my impatience
 
Sam

> Hello all
>   Is there a method to collect the items in an array into a hash
>
> I want to go from this X =[1,2,3,4,5,6] to this Y={1 =>2, 3 =>4, 5
> =>6}
>
> Just seems like there should be one
>
> Thanks in advance
>
> Sam