Enumerators

suggest change

Versions

Enumerator has been in Ruby since 1.9. These notes were written through Ruby 2.4.

Introduction

An Enumerator is an object that implements iteration in a controlled fashion.

Instead of looping until some condition is satisfied, the object enumerates values as needed. Execution of the loop is paused until the next value is requested by the owner of the object.

Enumerators make infinite streams of values possible.

Parameters

Parameter Details
yielder The block argument. It responds to yield, aliased as <<. Yielding to it supplies the next value.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents