10.10. Enumerator semantics and uses

Now that you know how enumerators are wired and how to create them, we’re going to look at how they’re used—and why they’re used.

Perhaps the hardest thing about enumerators, because it’s the most difficult to interpret visually, is how things play out when you call the each method. We’ll start by looking at that; then, we’ll examine the practicalities of enumerators, particularly the ways in which an enumerator can protect an object from change and how you can use an enumerator to do fine-grained, controlled iterations. We’ll then look at how enumerators fit into method chains in general and we’ll see a couple of important specific cases.

10.10.1. How to use an enumerator’s each method

An enumerator’s each ...

Get The Well-Grounded Rubyist, 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.