From: Joel VanderWerf Date: 2005-04-29T03:44:09+09:00 Subject: Re: Deep copy? Andrew Walrond wrote: > Is there a deep copy function that I've missed somehow? (dup and clone are > both shallow copy functions). > > E.g. How can I make a deep copy of a Hash? > > Ie if > a=['who'=>'me'], > I want > b = a.deepcopy > Such that > b['who'].replace('you') > doesn't result in > a == ['who'=>'you'] > > I could do > b=YAML::load(YAML::dump(a) > but it reeks of _wrongness_ ;) Marshal is a little less wrong than YAML, and it is AFAIK the most reliable and general deep copy in ruby. There was at one time some talk of general-purpose object traversal: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/64146