Enumerator Objects
external iteration.
External Iteration
An Enumerator is an object that represents an iteration. It supports external iteration: you pull values one at a time with next, instead of handing a block to each.
enum = [10, 20, 30].each
puts enum.next
puts enum.nextGetting an Enumerator
Call an iterator method like each with no block and you receive an Enumerator instead of running.
enum = [1, 2, 3].each
puts enum.classAll lessons in this course
- Writing Custom each
- Including Enumerable
- Lazy Enumerators
- Enumerator Objects