Exercise 38. Doing Things to Arrays


You have learned about arrays. When you learned about while-loops you “appended” numbers to the end of an array and printed them out. There were also Study Drills where you were supposed to find all the other things you can do to arrays in the Ruby documentation. That was a while back, so review those topics if you do not know what I’m talking about.

Found it? Remember it? Good. When you did this you had an array, and you “called” the function push on it. However, you may not really understand what’s going on so let’s see what we can do to arrays.

When you write mystuff.push('hello'), you are actually setting ...

Get Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition, Video Enhanced Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.