Class: Enumerator

Inherits:
Object show all
Defined in:
lib/backports/enumerator.rb

Defined Under Namespace

Classes: Yielder

Instance Method Summary collapse

Instance Method Details

#initialize_with_optional_block(*arg, &block) ⇒ Object



35
36
37
38
# File 'lib/backports/enumerator.rb', line 35

def initialize_with_optional_block(*arg, &block)
  return initialize_without_optional_block(*arg, &nil) unless arg.empty?  # Ruby 1.9 apparently ignores the block if any argument is present
  initialize_without_optional_block(Yielder.new(&block))
end

#nextObject

Raises:

  • (StopIteration)


4
5
6
7
8
9
# File 'lib/backports/enumerator.rb', line 4

def next
  require 'generator'
  @generator ||= Generator.new(self)
  raise StopIteration unless @generator.next?
  @generator.next
end

#rewindObject



11
12
13
14
15
16
# File 'lib/backports/enumerator.rb', line 11

def rewind
  require 'generator'
  @generator ||= Generator.new(self)
  @generator.rewind
  self
end