No doubt this question has been asked before but I cannot find it and it
is
not documented in three Ruby books I’ve checked, which is very strange
as
two dimensional arrays are a common need in programming.
How does one define and use a two dimensional array in Ruby?
I tried
anarray = [[1, 2, 3], [4, 5, 6] [7, 8, 9]]
with
puts anarray[1][1]
does not deliver the 5 that I would expect but instead, provides (in
SciTE)
the error message on the line defining the array:
ruby test_2_dimensional_array.rb
test_2_dimensional_array.rb:1:in `[]’: wrong number of arguments (3 for
(ArgumentError)
from test_2_dimensional_array.rb:1
Exit code: 1
So what is the secret for working with two dimensional arrays in Ruby?
And
is it documented somewhere?
Thanks in advance!