Arrays of Arrays: Two-dimensional arrays
Learn about 2D arrays and how they are used in Ruby.
Initializing different types of arrays
We can specify any type while initializing arrays. For example, string:
$ irb
> Array.new(10, 'hello')
=> ["hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello"]
Or Boolean:
Note: Boolean type doesn’t exist in Ruby but, in this course, we intentionally refer to both
theTrueClass
andFalseClass
types as Boolean.
$ irb
> Array.new(10, true)
=> [true, true, true, true, true, true, true, true, true, true]
Or integer:
$ irb
> Array.new(10, 123)
=> [123, 123, 123, 123, 123, 123, 123, 123, 123, 123]
In other words, ...