Module: Katuv::NodeBehavior
- Defined in:
- lib/katuv/node_behavior.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #arity ⇒ Object
- #block ⇒ Object
- #children ⇒ Object
- #each(&block) ⇒ Object
- #has_children? ⇒ Boolean
- #initialize(name = nil, opts = {}, &block) ⇒ Object
- #parameters ⇒ Object
- #run!(&block) ⇒ Object
- #terminal? ⇒ Boolean
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/katuv/node_behavior.rb', line 10 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
10 11 12 |
# File 'lib/katuv/node_behavior.rb', line 10 def parent @parent end |
Instance Method Details
#arity ⇒ Object
22 23 24 |
# File 'lib/katuv/node_behavior.rb', line 22 def arity @block.arity end |
#block ⇒ Object
16 17 18 19 20 |
# File 'lib/katuv/node_behavior.rb', line 16 def block # pretend there's no method if we're not a terminal class. raise NoMethodError unless terminal? @block end |
#children ⇒ Object
38 39 40 |
# File 'lib/katuv/node_behavior.rb', line 38 def children @children ||= {} end |
#each(&block) ⇒ Object
30 31 32 |
# File 'lib/katuv/node_behavior.rb', line 30 def each(&block) children.values.each(&block) end |
#has_children? ⇒ Boolean
42 43 44 |
# File 'lib/katuv/node_behavior.rb', line 42 def has_children? children.any? end |
#initialize(name = nil, opts = {}, &block) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/katuv/node_behavior.rb', line 3 def initialize(name = nil, opts = {}, &block) @parent = opts[:parent] @name = name @opts = opts @block = block run! &block unless terminal? end |
#parameters ⇒ Object
26 27 28 |
# File 'lib/katuv/node_behavior.rb', line 26 def parameters @block.parameters end |
#run!(&block) ⇒ Object
34 35 36 |
# File 'lib/katuv/node_behavior.rb', line 34 def run!(&block) instance_eval &block if block_given? end |
#terminal? ⇒ Boolean
12 13 14 |
# File 'lib/katuv/node_behavior.rb', line 12 def terminal? self.class.terminal? end |