More Array Methods

We’ve learned each, but there are many other array methods, almost as many as there are string methods. In fact, some of them (such as length, reverse, +, and *) work just like they do for strings, except they operate on the slots of the array rather than on the letters of the string. Others, such as last and join, are specific to arrays. Still others, such as push and pop, actually change the array. And just as with the string methods, you don’t have to remember all of these, as long as you can remember where to find out about them (and that would be right here).

Let’s look at to_s and join. to_s gives you a nice readable string description, in this case making it clear that this is an array of strings. join calls to_s ...

Get Learn to Program, 2nd 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.