From: Stefano Crocco Date: 2007-09-26T16:01:16+09:00 Subject: Re: merge two arrays into a hash Alle mercoled狸 26 settembre 2007, Jan Ask ha scritto: > 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? > > Thanks a lot require 'generator' h = {} SyncEnumerator.new(key, value).each{|i| h[i[0]] = (i[1]|| "")} p h => {'1'=>'a', '2'=>'b', '3'=>''} I hope this helps Stefano