I found a good (and simple) example of Enumerators (Ruby 1.9) in the
pickaxe book, the triangular_numbers from which I devised a simpler
(although rather useless) example:
m = Enumerator.new { |yielder| loop {yielder.yield 1 } }
I faithfully copied that 'yielder' parameter but to be honest I don't
understand where it is defined. Is it possible to modify it? It looks
like an usual code block which gets called with a parameter.
I found a good (and simple) example of Enumerators (Ruby 1.9) in the
pickaxe book, the triangular_numbers from which I devised a simpler
(although rather useless) example:
m = Enumerator.new { |yielder| loop {yielder.yield 1 } }
I faithfully copied that 'yielder' parameter but to be honest I don't
understand where it is defined. Is it possible to modify it?
Modify what? The block parameter contains an instance of
Enumerator::Yielder, which is used to pass control around.