From: Wu Ning Date: 2008-01-03T21:11:29+09:00 Subject: Re: has any one tried this? Thanks, I know what's going on now, :) Daniel Lucraft wrote: > 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. >> I just wannt insert into a 1 into the third array of a. > > After a = Array.new(3,Array.new()), a is an array containing three > references to the same object. There is only one array, but it is > repeated three times. > > Do > a = []; 3.times { a << [] } > and you'll have three different arrays. > > best, > Dan -- Posted via http://www.ruby-forum.com/.