From: Hal Fulton Date: 2004-04-27T09:20:58+09:00 Subject: Re: The Strangeness of Arrays Roger Bannister wrote: > Hi > > The behaviour below has me completely confuzzled. Why on earth does my > array suddenly have all rows equal to the last row? > > Can anyone tell me if this is expected; or if I have to start wearing my > Stupid Hat again. It's the strangeness of objects, not arrays. See below... > Thanks > R > > irb(main):014:0> @t = Array.new(5, Array.new(4)) This fills @t with five references to the same four-item array. If you change one, you change them all. I think in recent Ruby you can do this: @t = Array.new(5) { Array.new(4) } and you'll get different sub-arrays. Try it... Hal