From: timr Date: 2009-12-29T17:05:04+09:00 Subject: Re: PLEASE HELP...dup is not working correctly in the following code On Dec 28, 10:49 pm, Rimantas Liubertas wrote: > > #dup creates a copy of an object with a different object_id. As > > follows: > > <…> > > > > > > >> a = ["bar", "baz"] > => ["bar", "baz"] > >> b = a.dup > => ["bar", "baz"] > >> c = Marshal.load(Marshal.dump(a)) > => ["bar", "baz"] > >> b[0] << "s" > => "bars" > >> b > => ["bars", "baz"] > >> a > => ["bars", "baz"] > >> c > => ["bar", "baz"] > >> a.object_id > => 2157344160 > >> b.object_id > => 2157338800 > >> c.object_id > => 2157328340 > >> a[0].object_id > => 2157344140 > >> b[0].object_id > => 2157344140 > >> c[0].object_id > > => 2157328320 > > Regards, > Rimantas > --http://rimantas.com This is in effect the deep copy of a complex array containing strings that we were pining for. I think it is easier to do it this ways than to map through all of the nested arrays. Thanks for the irb demo of its use.