Method deprecated or moved
This method is deprecated or moved on the latest stable version.
The last existing version (v1_8_7_330) is shown here.
new(enum = nil, &block)
public
Creates a new generator either from
an Enumerable object or from a block.
In the former, block is ignored even if given.
In the latter, the given block is called with the generator itself, and
expected to call the yield
method for each element.
# File lib/generator.rb, line 69
def initialize(enum = nil, &block)
if enum
@block = proc { |g|
enum.each { |x| g.yield x }
}
else
@block = block
end
@index = 0
@queue = []
@cont_next = @cont_yield = @cont_endp = nil
if @cont_next = callcc { |c| c }
@block.call(self)
@cont_endp.call(nil) if @cont_endp
end
self
end