From: coolgeng coolgeng Date: 2007-09-26T16:56:48+09:00 Subject: Re: merge two arrays into a hash ------=_Part_6364_20368467.1190793406918 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/26/07, Daniel Sheppard wrote: > > > > myhash = {} > > > key.zip(value) {|a,b| myhash[a] = b } > > > > > > It does not work! > > irb(main):017:0> key.zip(value){|a,b| myhash[a] = b} > > => nil > > The result is in my_hash > > irb(main):014:0> myhash = {} > => {} > irb(main):015:0> key.zip(value) {|a,b| myhash[a] = b } > => nil > irb(main):016:0> myhash > => {"1"=>"a", "2"=>"b", "3"=>nil} > > Thanks a lot! By the way, what is the different between special case and general case? 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 -- Best Regards Cooper Geng ------=_Part_6364_20368467.1190793406918--