From: Matthew Margolis Date: 2004-09-21T10:35:12+09:00 Subject: Re: Filling a 2D array Mehr, Assaph (Assaph) wrote: > > >>>@tileArray = Array.new() >>>@height.times {@tileArray.push Array.new(@width, Tile.new)} >>> >>> > > > >>@height.times {@tileArray.push Array.new{@width, Tile.new}} >> >> > >Gah, posted too soon! > ># initialize an array of arrays: >@tileArray = Array.new(@height) { Array.new } ># Initizlize arrays of tiles: >@height.times { @tileArray.push Array.new(@width) {Tile.new} } > >Comment still stands though: > > > >>As always, when you need to initialize an array with new objects per >>cell (rather than references to the same object) use the block form. >>You had initialized the first array correctly, but must have mistyped >>for the inner array creation :-) >> >> > > > > > > Ah, that makes sense. Thank you, Matthew Margolis