Robert Klemme
10/29/2008 4:53:00 PM
On 29.10.2008 17:26, Kyle Schmitt wrote:
> Ahh.
> And upon not being lazy and looking at the C, I see this...
> ary2 = ary_new(rb_obj_class(ary), len);
>
> Which I'm guessing is equivalent to this in ruby (which I already knew
> would return the same array len times)
> ary2=Array.new(ary,len)
>
> Any chance the document maintainer could slip the word "shallow" into
> the description of array*?
Dunno. But all (or almost all) copies (e.g. dup, clone, Enumerable#map,
Enumerable#select) do shallow copying only. So shallow is the rule and
not particularly exceptional - as it is also more efficient and deep
copy is more complex (i.e. deciding when to create a new object or just
copy the reference). There are quite a few discussions of this topic in
the archives...
For deep copies the idiom probably most often used is
copy = Marshal.load(Marshal.dump(obj))
Kind regards
robert