From: Robert Klemme Date: 2008-10-30T01:54:30+09:00 Subject: Re: Bug or not a bug? array*=int 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