6.3. Conclusion

In this chapter we’ve seen what symbols are in Ruby and how they are used. We’ve seen both standard and user-defined uses of symbols.

We’ve also looked at ranges in depth. We’ve seen how to convert them to arrays, how to use them as array or string indices, how to iterate over them, and other such operations. We’ve looked in detail at the flip-flop operator (and an alternative to the old syntax). Finally we’ve seen in detail how to construct a class so that it works well with range operators.

That ends our discussion of symbols and ranges. But as they are commonly used in Ruby (and are extremely useful), you’ll see more of them both in incidental code throughout the rest of the book.

Get The Ruby Way: Solutions and Techniques in Ruby Programming, Second 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.