From: skibud2 Date: 2007-08-02T02:30:12+09:00 Subject: Ruby Array to Hash (a better way?) 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"} My Current Code: def array_to_hash(array) count = 0 hash = Hash.new (array.length / 2).times do hash[array[count]] = array[count+1] count += 2 end return hash end