Tutorial by Examples

Let's first recap how to initialize a 1D ruby array of integers: my_array = [1, 1, 2, 3, 5, 8, 13] Being a 2D array simply an array of arrays, you can initialize it like this: my_array = [ [1, 1, 2, 3, 5, 8, 13], [1, 4, 9, 16, 25, 36, 49, 64, 81], [2, 3, 5, 7, 11, 13, 17] ]
You can go a level further down and add a third layer of arrays. The rules don't change: my_array = [ [ [1, 1, 2, 3, 5, 8, 13], [1, 4, 9, 16, 25, 36, 49, 64, 81], [2, 3, 5, 7, 11, 13, 17] ], [ ['a', 'b', 'c', 'd', 'e'], ['z', 'y', 'x', 'w', 'v'] ], [ [] ...
Accessing the 3rd element of the first subarray: my_array[1][2]
Given a multidimensional array: my_array = [[1, 2], ['a', 'b']] the operation of flattening is to decompose all array children into the root array: my_array.flatten # [1, 2, 'a', 'b']

Page 1 of 1