From: "Shot (Piotr Szotkowski)" Date: 2009-11-14T22:26:40+09:00 Subject: Re: how to copy array in ruby --/04w6evG8XlLl3ft Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Ralph Shnelvar: > Is there a way to make a deep copy? That is ... in the code > below, could b.dup be replaced with something like b.deepdup? If the contents of the array are marshalable, you can try the idiomatic Marshal.dump/Marshal.load cycle: >> array =3D [[:a1, :a2], :b] =3D> [[:a1, :a2], :b] >> dup =3D array.dup =3D> [[:a1, :a2], :b] >> dup[0] << :a3 =3D> [:a1, :a2, :a3] >> dup =3D> [[:a1, :a2, :a3], :b] >> array =3D> [[:a1, :a2, :a3], :b] >> deep =3D Marshal.load Marshal.dump(array) =3D> [[:a1, :a2, :a3], :b] >> deep[0] << :a4 =3D> [:a1, :a2, :a3, :a4] >> deep =3D> [[:a1, :a2, :a3, :a4], :b] >> array =3D> [[:a1, :a2, :a3], :b] =E2=80=94 Shot --=20 Add argentinas-dst-2009.diff: Disable DST switch for Argentina tomorrow, as the Argentina government decided yesterday. Careful planning is boring. [Martin Pitt, tzdata 2009n-0ubuntu0.9.04.1 changelog] --/04w6evG8XlLl3ft Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkr+sAoACgkQi/mCfdEo8UpTbwCgj/RhcQWam2nPpDf3IrK4pyXS r+YAoKVNtWNIc79rJ5PWymTYh60r5/dJ =DnOm -----END PGP SIGNATURE----- --/04w6evG8XlLl3ft--