Module: Katuv::NodeBehavior

Defined in:
lib/katuv/node_behavior.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/katuv/node_behavior.rb', line 10

def name
  @name
end

#parentObject (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

#arityObject



22
23
24
# File 'lib/katuv/node_behavior.rb', line 22

def arity
  @block.arity
end

#blockObject

Raises:

  • (NoMethodError)


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

#childrenObject



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

Returns:

  • (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

#parametersObject



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

Returns:

  • (Boolean)


12
13
14
# File 'lib/katuv/node_behavior.rb', line 12

def terminal?
  self.class.terminal?
end