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

Understanding Lazy Enumerables

Let’s do a brief recap on terminology before we dive into lazy enumerables. What’s the difference between an enumerable and an enumerator?

In Ruby, an Enumerable is a collection class (such as Array and Hash) that contains methods for traversal, searching, and sorting.

An Enumerator, on the other hand, is an object that performs the actual enumeration. There are two kinds of enumeration—internal and external—which will be explained in External vs. Internal Iteration.

Lazy enumeration was introduced in Ruby 2.0. What exactly is lazy? Is Ruby trying to slack off? Well, the “lazy” in lazy enumeration refers to the style of evaluation. To understand this better, let’s review the opposite of lazy evaluation: ...

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