Class: CallableTree::Node::Internal::Strategy::Compose
- Inherits:
-
Object
- Object
- CallableTree::Node::Internal::Strategy::Compose
- Includes:
- CallableTree::Node::Internal::Strategy
- Defined in:
- lib/callable_tree/node/internal/strategy/compose.rb
Instance Method Summary collapse
- #call(nodes, *inputs, **options) ⇒ Object
-
#initialize(matchable: true, terminable: false) ⇒ Compose
constructor
A new instance of Compose.
Methods included from CallableTree::Node::Internal::Strategy
#==, #eql?, #hash, #matchable?, #name, #terminable?
Constructor Details
#initialize(matchable: true, terminable: false) ⇒ Compose
Returns a new instance of Compose.
10 11 12 13 |
# File 'lib/callable_tree/node/internal/strategy/compose.rb', line 10 def initialize(matchable: true, terminable: false) self.matchable = matchable self.terminable = terminable end |
Instance Method Details
#call(nodes, *inputs, **options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/callable_tree/node/internal/strategy/compose.rb', line 15 def call(nodes, *inputs, **) head, *tail = inputs nodes.reduce(head) do |input, node| if matcher.call(node, input, *tail, **) output = node.call(input, *tail, **) break output if terminator.call(node, output, input, *tail, **) output else input end end end |