Filling a 2D array

Discussion in 'Ruby' started by Matthew Margolis, Sep 21, 2004.

  1. @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
    Matthew Margolis, Sep 21, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    12
    Views:
    573
    Vladimir
    Nov 22, 2005
  2. MarsTeam

    int array filling

    MarsTeam, Oct 15, 2007, in forum: C Programming
    Replies:
    0
    Views:
    342
    MarsTeam
    Oct 15, 2007
  3. Josselin
    Replies:
    11
    Views:
    212
    Robert Klemme
    Oct 21, 2006
  4. Mohsen Pahlevanzadeh
    Replies:
    0
    Views:
    115
    Mohsen Pahlevanzadeh
    Sep 9, 2013
  5. MRAB
    Replies:
    0
    Views:
    115
Loading...

Share This Page