Class: EM::Sequence::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/em-sequence/block.rb

Overview

Block caller sequence item.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, args) ⇒ Block

Constructor.

Parameters:

  • body (Proc)

    body of the block

  • args (Array)

    input variables specification



46
47
48
49
# File 'lib/em-sequence/block.rb', line 46

def initialize(body, args)
    @body = body
    @args = args
end

Instance Attribute Details

#argsArray

Input variables specification.

Returns:

  • (Array)


36
37
38
# File 'lib/em-sequence/block.rb', line 36

def args
  @args
end

#bodyProc

Holds body of the block.

Returns:

  • (Proc)


28
29
30
# File 'lib/em-sequence/block.rb', line 28

def body
  @body
end

Instance Method Details

#call(vars, &block) ⇒ Object

Calls the block.

Parameters:

  • vars (Hash)

    data hash with current variables state

  • block (Proc)

    block for giving back the call result



58
59
60
61
62
# File 'lib/em-sequence/block.rb', line 58

def call(vars, &block)
    call_args = vars.values_at(*@args)
    result = @body.call(*call_args)
    block.call(result, result)
end