From: Frederick Cheung Date: 2008-01-03T20:32:21+09:00 Subject: Re: has any one tried this? On 3 Jan 2008, at 11:21, Wu Ning wrote: > My ruby version is 1.8.6 > a = Array.new(3,Array.new()) > a[2]<<1 > puts a > > the result of a is > [[1], [1], [1]] > in irb.. > > I don't understand why. Array.new will insert the second argument you give into the array (3 times since that's what you've asked for). However it's the same array (You can see this quite easily if you do Array.new(3,Array.new).map {| x| x.object_id}). So a is not an array containing 3 arrays, it's an array containing the same array 3 times. a = Array.new(3) {[]} should do the trick (since the block is called once for each element of the array) Fred > > I just wannt insert into a 1 into the third array of a. > -- > Posted via http://www.ruby-forum.com/. >