M
Mason Kelsey
[Note: parts of this message were removed to make it a legal post.]
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:
(ArgumentError)
from test_2_dimensional_array.rb:1
So what is the secret for working with two dimensional arrays in Ruby? And
is it documented somewhere?
Thanks in advance!
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:
test_2_dimensional_array.rb:1:in `[]': wrong number of arguments (3 for 2)ruby test_2_dimensional_array.rb
(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!