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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: array to hash
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password