Working with Arrays
Get yourself versed in Arrays and how to operate on them in Ruby!
Arrays are like bags that contain things
While numbers, Strings, true
, false
, and nil
all represent simple,
primitive things, Arrays are more interesting, and very useful.
💡
An Array is an object that stores other objects.
An Array is created by separating values by commas, and enclosing this list with square brackets, like so:
[1, 2, 3]
This is a simple Array that holds three numbers.
An Array is created by listing objects, separated by commas, and enclosed by square brackets.
Arrays can contain all kinds of things:
["A string", 1, true, :symbol, 2]
This creates an Array with 5 elements, i.e. a bag that contains 5 things: a
string, a number, true
, a symbol, and another number.
💡
Arrays can contain all kinds of objects.
Note that in Ruby ...
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy