From: Gordon Thiesfeld Date: 2007-08-02T02:34:59+09:00 Subject: Re: Ruby Array to Hash (a better way?) On Aug 1, 12:26 pm, skibud2 wrote: > Hey Guys, > > I want to convert an array like the following to a hash. Below is my > current code (I am assuming there is a better way). > > Thanks > > ["foo", "bar", "foo1", "bar1","foo2", "bar2"] convert to > {"foo"=>"bar", "foo1"=>"bar1","foo2"=>"bar2"} Use Hash#[] >> Hash["foo", "bar", "foo1", "bar1","foo2", "bar2"] => {"foo1"=>"bar1", "foo2"=>"bar2", "foo"=>"bar"} hth Gordon