Class: EM::Sequence::Method

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

Overview

Method caller sequence item.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, name, args, metablock) ⇒ Method

Constructor.

Parameters:

  • target (Object)

    target (parent) object instance of the call

  • name (Symbol)

    method name

  • args (Array)

    input variables specification

  • metablock (Proc)

    returning variables specification block



64
65
66
67
68
69
# File 'lib/em-sequence/method.rb', line 64

def initialize(target, name, args, metablock)
    @target = target
    @name = name
    @args = args
    @metablock = metablock
end

Instance Attribute Details

#argsArray

Input variables specification.

Returns:

  • (Array)


44
45
46
# File 'lib/em-sequence/method.rb', line 44

def args
  @args
end

#metablockProc

Block which returns returned variables specification.

Returns:

  • (Proc)


52
53
54
# File 'lib/em-sequence/method.rb', line 52

def metablock
  @metablock
end

#nameSymbol

Holds method name.

Returns:

  • (Symbol)


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

def name
  @name
end

#targetObject

Holds method target object.

Returns:

  • (Object)


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

def target
  @target
end

Instance Method Details

#call(vars, &block) ⇒ Object

Calls the method.

Parameters:

  • vars (Hash)

    data hash with current variables state

  • block (Proc)

    block for giving back the call result



78
79
80
81
82
83
84
# File 'lib/em-sequence/method.rb', line 78

def call(vars, &block)
    call_args = vars.values_at(*@args)
    @target.send(@name, *call_args) do |*returns|
        result = __combine(self.meta, returns)
        block.call(result, returns.first)
    end
end