Building Our Skeleton

First, you have to decide where the implementation should live. To do that, you have to find out where the Enumerator::Lazy method lives. If you head over to the official documentation, you might find a clue shown in the figure.

images/cheap_counterfeiting/rubydoclazyenum.png

So, the Enumerator class is the parent of the Lazy class. This is easy enough to translate to code:

 class​ Lazy < Enumerator
 end

For our exercise, we’ll use another name instead of reopening the existing Ruby class. A quick trip to the thesaurus yields a synonym to Lazy. Introducing, Lax:

 class​ Lax < Enumerator
 end

Notice that we’re inheriting from ...

Get Mastering Ruby Closures 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.