#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Need help with object movement in 2d array.


    What is the best way to iterate through a 2d array in ruby.
  2. #2
  3. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    I'm fairly new to Ruby myself, so I cannot say what the best way is, but I can see that a fairly easy way would be

    Code:
    a.each {|b| b.each {|c| c.do_something}}
    This would be equivalent to
    Code:
    a.each do |b|
        b.each do |c|
            c.do_something
        end
    end
    Whether there is a better way would probably depend on the details of what you're trying to do, I suppose. Could you give us more information on what you need to do?
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov

IMN logo majestic logo threadwatch logo seochat tools logo