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. Advertisements

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:
    704
    Vladimir
    Nov 22, 2005
  2. MarsTeam

    int array filling

    MarsTeam, Oct 15, 2007, in forum: C Programming
    Replies:
    0
    Views:
    441
    MarsTeam
    Oct 15, 2007
  3. Josselin
    Replies:
    11
    Views:
    325
    Robert Klemme
    Oct 21, 2006
  4. Josselin

    Nested array filling bad..

    Josselin, Sep 23, 2007, in forum: Ruby
    Replies:
    4
    Views:
    187
    Josselin
    Sep 24, 2007
  5. Josselin
    Replies:
    0
    Views:
    202
    Josselin
    Sep 24, 2007
  6. Thufir
    Replies:
    2
    Views:
    238
    Thufir
    Nov 10, 2007
  7. Indra M.
    Replies:
    4
    Views:
    186
    Robert Dober
    Jul 22, 2008
  8. Mohsen Pahlevanzadeh
    Replies:
    0
    Views:
    295
    Mohsen Pahlevanzadeh
    Sep 9, 2013
Loading...