From: "Thomas B." Date: 2008-08-29T01:12:00+09:00 Subject: Re: Dumb "array of arrays" question Hello Richard, RichardOnRails wrote: > My minor exception is that an array IS an object, so the two > paragraphs sound weird. He is contrasting an object of class Object > to an object of class Array. > > 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. But there is a method to check it: equal?. It works like == in Java. a=[whatever] a.equal?(a) #=> true # the very same Array instance a.equal?(a.dup) #=> false # it's another instance, only it looks like the old one when inspect'ed But still the whatever inside a and a.dup is exactly the same thing: a[0].euqal?(a.dup[0]) #=> true That proves the copy is shallow - there's a new object, but it holds old references. > 3: [#]; #; Array > 4: [#]; #; Array The [#]'s here are in fact different objects, only they look the same. Hope that helps a bit. T. -- Posted via http://www.ruby-forum.com/.