From: Farrel Lifson Date: 2007-09-26T16:02:00+09:00 Subject: Re: merge two arrays into a hash On 26/09/2007, Jan Ask wrote: > Hi all, > > I have looked at some of the answers in the forum, but they do not seem > to fit. I want to merge two array into a hash like so: > > key = [ "1", "2", "3"] > value = [ "a", "b" ] > > into: > > myhash = {'1' => 'a' , '2' => 'b' , '3' => ''} > > Can this be done without creating new classes and methods? irb(main):001:0> key = ["1","2","3"] => ["1", "2", "3"] irb(main):002:0> value = ["a","b","c"] => ["a", "b"] irb(main):009:0> Hash[*key.zip(value).flatten] => {"1"=>"a", "2"=>"b", "3"=>nil}