Arrays
Goals
Step 1
Type this in irb:fruits = ["kiwi", "strawberry", "plum"]Type this in irb:things = [5, 'tree', 19.5] things.lengthType this in irb:empty_array = [] empty_array.length
Step 2
Type this in irb:fruits[0] fruits[1] fruits[2]Type this in irb:fruits.first fruits.last
Step 3
Type this in irb:['salt'] + ['pepper']Type this in irb:fruits + ['mango'] fruits
Step 4
Type this in irb:fruits = ["kiwi", "strawberry", "plum"] fruits.push('apple') fruits.pop()
Explanation
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 Type this in irb:[].pop 3.0.pop
Further Reading
Ruby's documentation for Array
Next Step:
Go on to Hashes