From: coolgeng coolgeng Date: 2007-09-26T16:23:51+09:00 Subject: Re: merge two arrays into a hash ------=_Part_6260_7832655.1190791431204 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/26/07, Daniel Sheppard wrote: > > > key = [ "1", "2", "3"] > > value = [ "a", "b" ] > > > > into: > > > > myhash = {'1' => 'a' , '2' => 'b' , '3' => ''} > > For the special case where key and value do not contain arrays: > > Hash[*key.zip(value).flatten] > > For the general case: > > myhash = {} > key.zip(value) {|a,b| myhash[a] = b } > > Dan > > > It does not work! irb(main):017:0> key.zip(value){|a,b| myhash[a] = b} => nil -- Best Regards Cooper Geng ------=_Part_6260_7832655.1190791431204--