On 8/28/08, Thomas B. <tpreal / gmail.com> wrote:
> Hello Richard,
>
> RichardOnRails wrote:
> > More importantly,  according to my tests below,  dup'ing an array does
> > NOT make a new array.  It returns the (address of/pointer to) the same
> > old array.
>
> dup'ing an array DOES make a new array, only the new array looks like
> the old one, because Array#inspect doesn't return the address of the
> array so you cannot see if it is exactly the same instance or not.

> > 3: [#<Object:0x2808138>]; #<Object:0x2808138>; Array
> > 4: [#<Object:0x2808138>]; #<Object:0x2808138>; Array
>
> The [#<Object:0x2808138>]'s here are in fact different objects, only
> they look the same.
>
You can prove they are different objects this way:
code:
   a = [Object.new]; ad = a.dup
   puts a.inspect+ ", #{a.object_id}"
   puts ad.inspect+ ", #{ad.object_id}"
output:
[#<Object:0x2842310>], 21107090
[#<Object:0x2842310>], 21107070

-Adam