From: Jamis Buck Date: 2005-10-22T04:38:46+09:00 Subject: Re: array in hash... argh!! On Oct 21, 2005, at 1:26 PM, Marco wrote: > hello all. > i hope someone here can help me out. i really don't understand haw > to do this. > i have a hash like this: I'm always up for a good game of golf. :) > > "movies"=>{ > "title"=>["ciccio", "test", "ciccio panza"], > "id"=>["3", "4", "1"], > "description"=>["1", "", "hey?"], > "insert_date"=>["2005-10-19", "2005-10-20", "2005-10-18"] > } hashes = [] hash["movies"].keys.each do |key| hash["movies"][key].each_with_index do |value, idx| hashes[idx] ||= {} hashes[idx][key] = value end end p hashes Not optimized for brevity, but it works. - Jamis > > and i wold like to get 3 hashes like tese: > > first hash: > "movie"=>{ > "title"=>"ciccio", > "id"=>"3", > "description"=>"1", > "insert_date"=>"2005-10-19" > } > > second hash: > "movie"=>{ > "title"=>"test", > "id"=>"4", > "description"=>"", > "insert_date"=>"2005-10-19" > } > > and so on. > > is this somehow possible? > thanks! > >