May 2022
Beginner
352 pages
7h 5m
English
In Chapter 2, we saw that strings can be thought of as sequences of characters in a particular order. In this chapter, we’ll learn about the array data type, which is the general Ruby container for a list of arbitrary elements in a particular order. We’ll start by explicitly connecting strings and arrays via the String#-split method (Section 3.1), and then learn about various other array methods throughout the rest of the chapter.
So far we’ve spent a lot of time understanding strings, and there’s a natural way to get from strings to arrays via the split method:
>> "ant bat cat".split(" ") # Split a string into a three-element array. => ["ant", "bat", "cat"]
We see from this result ...
Read now
Unlock full access