On Thu, 15 Nov 2001, Niko Schwarz wrote: > Hello out there, > maybe you can help me out: what do I do when I want a copy of a Hash, which > I can modify without altering the previous one? I tried already > Object#clone and Object#dup, but they didnt seem to copy anything... > my hash maps strings to arrays, which again holds integers. > would it help if id restructure it all, so that it maps strings to integers? > Try: class Object def deep_clone Marshal::load(Marshal.dump(self)) end end h1 = {"a" => [1], "b" => [2]} h2 = h1.deep_clone p h1.id p h2.id p(h1.id == h2.id) i1 = h1.to_a.map {|s,a| [s.id, a.id]}.flatten i2 = h2.to_a.map {|s,a| [s.id, a.id]}.flatten p(i1 == i2) p i1 p i2 /Robert