0Pricing
Ruby Academy · Lesson

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.next

Getting 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.class

All lessons in this course

  1. Writing Custom each
  2. Including Enumerable
  3. Lazy Enumerators
  4. Enumerator Objects
← Back to Ruby Academy