Class: Enumerator::Yielder

Inherits:
Object show all
Defined in:
lib/backports/1.9.1/enumerator/new.rb,
lib/backports/2.0.0/enumerable/lazy.rb

Overview

A simple class which allows the construction of Enumerator from a block

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Yielder

Returns a new instance of Yielder.



10
11
12
# File 'lib/backports/1.9.1/enumerator/new.rb', line 10

def initialize(&block)
  @final_block = block
end

Instance Attribute Details

#backports_memoObject

Current API for Lazy Enumerator does not provide an easy way to handle internal state. We “cheat” and use yielder to hold it for us. A new yielder is created when generating or after a ‘rewind`. This way we avoid issues like bugs.ruby-lang.org/issues/7691 or bugs.ruby-lang.org/issues/7696



19
20
21
# File 'lib/backports/2.0.0/enumerable/lazy.rb', line 19

def backports_memo
  @backports_memo
end

Instance Method Details

#<<(*arg) ⇒ Object



18
19
20
21
# File 'lib/backports/1.9.1/enumerator/new.rb', line 18

def <<(*arg)
  @final_block.call(*arg)
  self
end

#yield(*arg) ⇒ Object



14
15
16
# File 'lib/backports/1.9.1/enumerator/new.rb', line 14

def yield(*arg)
  @final_block.call(*arg)
end