From: dblack@... Date: 2002-08-14T11:38:47+09:00 Subject: Re: Is this array operation correct? Hello -- On Wed, 14 Aug 2002, Maur�cio wrote: > Hi, > > I've tried this: > > a = Array.new(3,[]) => [[], [], []] > a[1].push(3) => [[3],[3],[3]] > > > Is this correct? a[1].push(3) is the same as a[2].push(3)? If the > constructor creates the same copy for all array elements, shouldn't the > array create copies when writing? I'm not sure I follow the question, but the general thing going on is: a[0] and a[1] and a[2] are references to the same object, so if you change the object through one of those references, the change will be visible in all of them. It's as if you said: ar = [] a = [ ar, ar, ar ] ar.push(3) and then 'a' would look like: [[3],[3],[3]] David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav