Filling a 2D array

M

Matthew Margolis

@tileArray = Array.new()
@height.times {@tileArray.push Array.new(@width, Tile.new)}

I was hoping that the above code would create a 2D array filled with
Tile objects.
In Tile#initialize I have the simple line puts "orange"
When I run the code only #{height} "orange"s are printed to the
terminal. I assume that my code is only creating one Tile object per
row, how would one go filling the 2D array with unique Tiles?

Thank you,
Matthew Margolis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top