Step 13: Arrays

So far we’ve introduced some of the most basic data types in Ruby. Now you’re going to learn about another data type that is crucial to almost any Ruby program: the array. You can think of arrays as ordered lists of other objects. Arrays are surrounded in square brackets [ ], and each value in the array is separated by a comma.

[1, 2, 3, 4, 5]
["one", "two", "three", "four", "five"]

Arrays can hold values of different types, and can hold any type - even other arrays!

my_collection = [4, 8, 15, 16, 23, 42]
your_collection = [my_collection, 17, 19, 21]