From: Son SonOfLilit Date: 2006-06-03T23:20:07+09:00 Subject: Re: []= and two dimensional arrays ------=_Part_16381_29147029.1149344403829 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Thank you very much. Didn't know I could do a = Array.new(4) { Array.new(4) { "x" }} :-) Nive to learn something new. SonOfLilit On 6/3/06, Dave Burt wrote: > > OK, here's the key. > > a = Array.new.fill(Array.new.fill("x", 0, 4), 0, 4) > > 1) create an array (the inner "Array.new") > 2) fill it with 4 "x"s > 3) create another array (the outer "Array.new") > 4) fill it with 4 references to the first array > > What you want is probably: > > a = Array.new(4) { Array.new(4, "x") } > > or > > a = Array.new(4) { Array.new(4) { "x" }} > > That will create a new array for each of the four elements it > initializes the outer array with. > > The second version will give you 16 strings instead of just 4. > > Cheers, > Dave > > ------=_Part_16381_29147029.1149344403829--