Module: Yummi::BlockHandler

Included in:
Formatter::LogFormatter
Defined in:
lib/yummi.rb

Overview

A module to handle blocks by dynamically resolving parameters

see #DataEvalColorizer

Class Method Summary collapse

Class Method Details

.block_call(context, &block) ⇒ Object

Calls the block resolving the parameters by getting the parameter name from the given context.

Example

context = :max => 10, :curr => 5, ratio => 0.15
percentage = BlockHandler.call_block(context) { |max,curr| curr.to_f / max }


157
158
159
160
161
162
163
# File 'lib/yummi.rb', line 157

def block_call (context, &block)
  args = []
  block.parameters.each do |parameter|
    args << context[parameter[1]]
  end
  block.call(*args)
end