Class: CallableTree::Node::Internal::Pod
- Inherits:
-
Object
- Object
- CallableTree::Node::Internal::Pod
- Includes:
- CallableTree::Node::Internal
- Defined in:
- lib/callable_tree/node/internal/pod.rb
Overview
Pod: A node that can be instantiated directly with proc-based behavior. Provides an alternative to Builder style for inline node creation.
Usage patterns:
Constructor style: Pod.new(caller: ->(input, **) { input * 2 })
Factory style: Internal.create(caller: ->(input, **) { input * 2 })
Block style: Internal.create { |node| node.caller { |input, **| input * 2 } }
Direct Known Subclasses
Constant Summary
Constants included from Strategizable
Strategizable::DEFAUTL_FACTORY
Instance Attribute Summary
Attributes included from CallableTree::Node::Internal
Attributes included from CallableTree::Node
Instance Method Summary collapse
- #call(*inputs, **options) ⇒ Object
- #caller(proc = nil, &block) ⇒ Object
- #identifier(proc = nil, &block) ⇒ Object
- #identity ⇒ Object
-
#initialize(matcher: nil, caller: nil, terminator: nil, identifier: nil) {|_self| ... } ⇒ Pod
constructor
A new instance of Pod.
- #match?(*inputs, **options) ⇒ Boolean
-
#matcher(proc = nil, &block) ⇒ Object
DSL setters for block syntax.
- #terminate?(output, *inputs, **options) ⇒ Boolean
- #terminator(proc = nil, &block) ⇒ Object
Methods included from CallableTree::Node::Internal
#append, #append!, #children, #children!, create, #external?, #find, included, #internal?, #outline, #reject, #reject!, #shake, #shake!
Methods included from Strategizable
Methods included from CallableTree::Node
#ancestors, #depth, #external?, #internal?, #outline, #root?, #routes
Constructor Details
#initialize(matcher: nil, caller: nil, terminator: nil, identifier: nil) {|_self| ... } ⇒ Pod
Returns a new instance of Pod.
16 17 18 19 20 21 22 23 |
# File 'lib/callable_tree/node/internal/pod.rb', line 16 def initialize(matcher: nil, caller: nil, terminator: nil, identifier: nil) @_matcher = matcher @_caller = caller @_terminator = terminator @_identifier = identifier yield self if block_given? end |
Instance Method Details
#call(*inputs, **options) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/callable_tree/node/internal/pod.rb', line 54 def call(*inputs, **) return super unless @_caller @_caller.call(*inputs, **, _node_: self) do |*a, **o| super(*a, **o) end end |
#caller(proc = nil, &block) ⇒ Object
31 32 33 34 |
# File 'lib/callable_tree/node/internal/pod.rb', line 31 def caller(proc = nil, &block) @_caller = proc || block self end |
#identifier(proc = nil, &block) ⇒ Object
41 42 43 44 |
# File 'lib/callable_tree/node/internal/pod.rb', line 41 def identifier(proc = nil, &block) @_identifier = proc || block self end |
#identity ⇒ Object
70 71 72 73 74 |
# File 'lib/callable_tree/node/internal/pod.rb', line 70 def identity return super unless @_identifier @_identifier.call(_node_: self) { super } end |
#match?(*inputs, **options) ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'lib/callable_tree/node/internal/pod.rb', line 46 def match?(*inputs, **) return super unless @_matcher @_matcher.call(*inputs, **, _node_: self) do |*a, **o| super(*a, **o) end end |
#matcher(proc = nil, &block) ⇒ Object
DSL setters for block syntax
26 27 28 29 |
# File 'lib/callable_tree/node/internal/pod.rb', line 26 def matcher(proc = nil, &block) @_matcher = proc || block self end |
#terminate?(output, *inputs, **options) ⇒ Boolean
62 63 64 65 66 67 68 |
# File 'lib/callable_tree/node/internal/pod.rb', line 62 def terminate?(output, *inputs, **) return super unless @_terminator @_terminator.call(output, *inputs, **, _node_: self) do |o, *a, **opts| super(o, *a, **opts) end end |
#terminator(proc = nil, &block) ⇒ Object
36 37 38 39 |
# File 'lib/callable_tree/node/internal/pod.rb', line 36 def terminator(proc = nil, &block) @_terminator = proc || block self end |