| Class | Enumerator |
| In: |
lib/core/facets/enumerator.rb
lib/core/facets/enumerator/fx.rb lib/core/facets/enumerator/lazy/squeeze.rb |
| Parent: | Object |
| initialize | -> | old_initialize |
Provides the ruby-1.9 block form of Enumerator, where you can write:
obj = Enumerator.new do |yielder|
# ...
yielder.yield(data) # or: yielder << data
# ...
end
When obj.each is called, the block is run once. It should call yielder.yield with each item it wishes to generate.
Example:
fib = Enumerator.new { |y|
a = b = 1
loop {
y << a
a, b = b, a + b
}
}
fib.take(10) #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]