From: "Jermaine O." Date: 2012-11-06T22:59:23+09:00 Subject: Re: How to merge two or more hashes in to one? Jan E. wrote in post #1083135: > Hi, > > this is a very special form of "merging", so I don't think there's a > built-in method for this. > > But you can use the block form of Hash#merge: > > #------------------------------------- > foo = {"luxuy" => ["Mercedes", "BMW"], "sport" => ["Ferrari"]} > bar = {"luxuy" => ["BMW", "Bentley"], "sport"=>["Lamborghini"]} > > merg = foo.merge bar do |_, arr_1, arr_2| > arr_1 | arr_2 # array union > end > p merg > #------------------------------------- Thanks, that worked out, but I'm wondering how this applies when I have more than 2 hashes. Because then this wouldn't work. -- Posted via http://www.ruby-forum.com/.