Class: CallableTree::Node::Internal::Strategy::Broadcast

Inherits:
Object
  • Object
show all
Includes:
CallableTree::Node::Internal::Strategy
Defined in:
lib/callable_tree/node/internal/strategy/broadcast.rb

Instance Method Summary collapse

Methods included from CallableTree::Node::Internal::Strategy

#==, #eql?, #hash, #matchable?, #name, #terminable?

Constructor Details

#initialize(matchable: true, terminable: false) ⇒ Broadcast

Returns a new instance of Broadcast.

[View source]

10
11
12
13
# File 'lib/callable_tree/node/internal/strategy/broadcast.rb', line 10

def initialize(matchable: true, terminable: false)
  self.matchable = matchable
  self.terminable = terminable
end

Instance Method Details

#call(nodes, *inputs, **options) ⇒ Object

[View source]

15
16
17
18
19
20
21
22
23
24
# File 'lib/callable_tree/node/internal/strategy/broadcast.rb', line 15

def call(nodes, *inputs, **options)
  nodes.each_with_object([]) do |node, outputs|
    output = (node.call(*inputs, **options) if matcher.call(node, *inputs, **options))
    outputs << output

    break outputs if terminator.call(node, output, *inputs, **options)

    outputs
  end
end