Hi, I am trying to figure out how to add to a multi-dimensional array. I have:
array = Array.new
array.concat( [['a','b','c'], [[1,2,3],[2,3,4],[3,4,5]], ['D','E','F'],'Z'] )
puts array
array[3][0][0] = 'G' #my problem
As you might see I am trying to add 'G' to the cell [3][0][0]so the array would then look like:
[['a', 'b', 'c'], [[1, 2, 3], [2, 3, 4], [3, 4, 5]], ['D', 'E', 'F'], 'Z', [['G']] ]
unfourtionaly the book that I have does not cover multi-dimensional arrays. And Googleing did not help me.
EDIT: after a sec I noticed I already put something in the cell array[3], so I changed it to
array[4][0][0] = 'G' #and I get the error
"undefined method `[]' for nil:NilClass (NoMethodError)"
array = Array.new
array.concat( [['a','b','c'], [[1,2,3],[2,3,4],[3,4,5]], ['D','E','F'],'Z'] )
puts array
array[3][0][0] = 'G' #my problem
As you might see I am trying to add 'G' to the cell [3][0][0]so the array would then look like:
[['a', 'b', 'c'], [[1, 2, 3], [2, 3, 4], [3, 4, 5]], ['D', 'E', 'F'], 'Z', [['G']] ]
unfourtionaly the book that I have does not cover multi-dimensional arrays. And Googleing did not help me.
EDIT: after a sec I noticed I already put something in the cell array[3], so I changed it to
array[4][0][0] = 'G' #and I get the error
"undefined method `[]' for nil:NilClass (NoMethodError)"