More Array Methods

You’ve learned about each, but many other array methods exist, almost as many as string methods. In fact, some of them (such as length, reverse, +, and *) work the same way 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. 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 first. 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 on the ...

Get Learn to Program, 3rd 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.