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 off a chain of events inside Ruby to cause something to happen to the mystuff array. Here’s how it ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.