From: Stefano Crocco Date: 2008-12-28T20:02:36+09:00 Subject: Re: New to Ruby: copying arrays? Alle Sunday 28 December 2008, John Park ha scritto: > So here's my question.  Is there a simple and elegant way to duplicate > the entire content of a multi-dimensional array? You can use Marshal.dump and Marshal.load: a = [["a", "b"],["c", "d"]] b = Marshal.load(Marshal.dump(a)) a[0][0].upcase! puts a[0][0] #=> A puts b[0][0] #=> a Note that this only works if your array only contains serializable objects (in particular, it should not contain method or proc objects, IO objects and singleton objects). See the documentation for the Marshal module for more information (using the command ri marshal). >Oh, one more question: what's the difference between .dup and .clone >methods? As far as I know, the only difference is that clone also copies the frozen state of the original object, while dup doesn't: s1 = "test" s1.freeze s2 = s1.dup s3 = s1.clone puts s2.frozen? #=> false puts s3.frozen? #=> true I hope this helps Stefano