Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • generator.rb



Class/Module Index [+]



Public Instance Methods

next => object click to toggle source

Returns the next object in the enumerator, and move the internal position forward. When the position reached at the end, internal position is rewinded then StopIteration is raised.

Note that enumeration sequence by next method does not affect other non-external enumeration methods, unless underlying iteration methods itself has side-effect, e.g. IO#each_line.

Caution: This feature internally uses Generator, which uses callcc to stop and resume enumeration to fetch each value. Use with care and be aware of the performance loss.

               # File generator.rb, line 188
def next
  g = __generator
  return g.next unless g.end?

  raise StopIteration, 'iteration reached at end' 
rewind => e click to toggle source

Rewinds the enumeration sequence by the next method.

               # File generator.rb, line 200
def rewind

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.