"David Garamond" <lists / zara.6.isreserved.com> schrieb im Newsbeitrag
news:401169B2.7000503 / zara.6.isreserved.com...
> While reading the archives, I found out about this cool "idiom":
>
>   hash = Hash[*ary]
>
> which will turn [1,2,3,4] into {1=>2, 3=>4}. Is there anything similar
> to do the opposite (i.e., turn {1=>2, 3=>4} into [1,2,3,4] or
> [3,4,1,2])? I can only come up with this:
>
>   ary = Hash.to_a.flatten

You can use inject if you want to save the intermediate array:

irb(main):050:0> h=Hash[1,2,3,4]
=> {1=>2, 3=>4}
irb(main):051:0> h.inject([]){|arr,(key,val)| arr << key << val}
=> [1, 2, 3, 4]

Regards

    robert