Class: Backports::Yielder

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Yielder

Returns a new instance of Yielder.



104
105
106
# File 'lib/backports/tools.rb', line 104

def initialize(&block)
  @main_block = block
end

Instance Method Details

#each(&block) ⇒ Object



108
109
110
111
# File 'lib/backports/tools.rb', line 108

def each(&block)
  @final_block = block
  @main_block.call(self)
end

#yield(*arg) ⇒ Object



113
114
115
# File 'lib/backports/tools.rb', line 113

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