From: ptkwt@... (Phil Tomson) Date: 2004-01-24T14:09:57+09:00 Subject: Re: turning a hash into an array In article <401169B2.7000503@zara.6.isreserved.com>, David Garamond wrote: >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 > Well this is something I didn't know about till I saw Matz mention it in another thread today: irb(main):010:0> obj = {'a' => 1, 'b' => 2} => {"a"=>1, "b"=>2} irb(main):011:0> Array(obj) => [["a", 1], ["b", 2]] Now you could flatten it: irb(main):012:0> Array(obj).flatten => ["a", 1, "b", 2] Phil