From: dblack@... Date: 2006-08-14T00:47:04+09:00 Subject: Re: How to update nested Hashes? Hi -- On Mon, 14 Aug 2006, Hammed Malik wrote: > Given two nested Hashes, is there an easy way to update one with the other? > > a = {:top => {:foo => {:a => 1}, :bar => {:b => 2}}} > b = {:top => {:bar => {:c => 3}}} > > what I'd like is > > a.nested_update(b) => {:top => {:foo => {:a => 1}, :bar => {:c => 3}}} You could do something like: def a.nested_update(b) each_key {|k| self[k].update(b[k])} end David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <----- http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log http://www.manning.com/black => book, Ruby for Rails http://www.rubycentral.org => Ruby Central, Inc.