Index: lib/generator.rb =================================================================== --- lib/generator.rb (revision 20602) +++ lib/generator.rb (working copy) @@ -67,7 +67,7 @@ class Generator # In the latter, the given block is called with the generator # itself, and expected to call the +yield+ method for each element. def initialize(enum = nil, &block) - if enum + if @enum = enum @block = proc { |g| enum.each { |x| g.yield x } } @@ -148,6 +148,10 @@ class Generator # Rewinds the generator. def rewind() + if @enum && @enum.respond_to?(:rewind) + @enum.rewind + end + initialize(nil, &@block) if @index.nonzero? self