O'Reilly logo

Mastering Ruby Closures by Benjamin Tan Wei Hao

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required