From: jfn@... (Jeremy Nelson) Date: 2001-02-06T04:40:03+09:00 Subject: [ruby-talk:10383] Re: Multi-dimensional Array In article <95ia88$vuk$1@nnrp1.deja.com>, Jason wrote: >Hi All, > >a. Is a multi-dimensional array the best way to track this information? >b. Does Ruby have support for it? >c. Is there a better way to keep the information? I won't touch questions 'a' and 'c' because others have. But Ruby makes multi-dimensional arrays really easy to construct: class Matrix < Array def initialize (rows, columns) super(rows) self.each_index { |i| self[i] = Array.new(columns) self[i].each_index { |j| self[i][j] = rand(10) } } end end arr = Matrix.new(12, 15) arr.each { |i| p i } arr.each { |i| i.each { |j| p j } } arr.each_index { |i| arr[i].each_index { |j| puts "#{i},#{j} -> #{arr[i][j]}" } } Ruby is so much fun! =) Jeremy