class

Enumerator

v1_9_1_378 - Show latest stable - Superclass: Object

A class which provides a method `each’ to be used as an Enumerable object.

Included modules

  • Enumerable

Files

  • enumerator.c

1Note

Getting the return value from the underlying method of an Enumerator

stevecj · Sep 14, 2015

This is documented in the example code, but easy to miss.

When you get an Enumerator using #to_enum(:method_name, ...), you can get all of the yielded values using #next, but not the value that is finally returned.

That value can be retrieved via the #result attribute of the StopIteration exception object that is raised when calling #next after the underlying method has returned.