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.



153
154
155
# File 'lib/backports/tools.rb', line 153

def initialize(&block)
  @main_block = block
end

Instance Method Details

#each(&block) ⇒ Object



157
158
159
160
# File 'lib/backports/tools.rb', line 157

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

#yield(*arg) ⇒ Object



162
163
164
# File 'lib/backports/tools.rb', line 162

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