Flowdock
class
Importance_2
Ruby latest stable (v1_9_3_392) - 0 notes - Superclass: Object

Class deprecated or moved

This class is deprecated or moved on the latest stable version. The last existing version (v1_8_7_330) is shown here.

Generator converts an internal iterator (i.e. an Enumerable object) to an external iterator.

Note that it is not very fast since it is implemented using continuations, which are currently slow.

Example

require 'generator'

# Generator from an Enumerable object
g = Generator.new(['A', 'B', 'C', 'Z'])

while g.next?
  puts g.next
end

# Generator from a block
g = Generator.new { |g|
  for i in 'A'..'C'
    g.yield i
  end

  g.yield 'Z'
}

# The same result as above
while g.next?
  puts g.next
end
Show files where this class is defined (1 file)
Register or log in to add new notes.