Step 4

Ruby has many methods for modifying arrays. What did these two methods do?

Explanation

Arrays are used whenever you need to work with a large group of similar items.

A short list of methods for Array:

length

how long is this array (how many elements)

first

get the first element of the array (same as array[0])

last

get the last element of the array (same as array[-1])

push

add a new element to the end of the array

pop

remove (and return) the element at the end of the array

We are learning that different types of objects in ruby have different sets of methods. We can call pop on object of type Array, but we can't call it on an object of type Float.

Type this in irb:

[].pop
3.0.pop

In object oriented programming, each type of object shares a common list of methods. This list of methods is different for every type of object. When you attempt to call a method that is not available for the object's type, you get a NoMethodError and the interpreter stops running the program.