[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: array to hash

Harry

3/20/2007 11:47:00 AM

On 3/20/07, Servando Garcia <garcia.servando@gmail.com> wrote:
>
> 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

Try this


arr = [1,2,3,4,5,6]
ahash = Hash[*arr]
p arr
p ahash

Harry

--

http://www.kakueki.com/ruby...
Japanese Ruby List Subjects in English