Enumerator
Nearly every Enumerable method that takes a block argument can also be called without a block, in which case the method returns an Enumerator. (There are a few subclasses of Enumerator that you wouldn’t create by hand but which implement some specialized logic.) In addition to those Enumerable methods, you can create an enumerator in a few other ways.
Creating Enumerators
Any object can be converted into an Enumerator with the Object#to_enum(method = :each, *args) method (aliased as enum_for). The first argument to to_enum is a symbol that’s the name of a method that converts the object to something enumerable. Any further arguments to to_enum are passed to the method named in the first argument. You can then treat that enumerator ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access