From: RichardOnRails Date: 2008-08-26T09:20:40+09:00 Subject: Re: Dumb "array of arrays" question On Aug 25, 6:57 pm, RichardOnRails wrote: > Hi, > > I wrote the following intending to create an array of 3 element, each > being itself an array of two elements initialized to zero; Judging by > "inspect", I seem to have that: > > a = Array.new(3, [0,0]) => [[0, 0], [0, 0], [0, 0]] > > I tried the following, which confirms that a[0] is indeed a sub- > array. > > a[0].inspect + "; " + a[0].class.to_s => [0, 0]; Array > > Then I tried to assign a number (5) to the first element of the first > sub-array. What I got was more 5's than I bargained for: > > a[0][0]=5 => [[5, 0], [5, 0], [5, 0]] > > What am I missing here? > > Thanks in Advance, > Richard Hi y'all, Many thanks. Thanks to Michael for being first with a quick solution Thanks to Todd for suggesting what might be more elegant in certain circumstances. Thanks to Chris for revealing exact how Ruby handles my construct and the one I really want. Best wishes, Richard