Class: Rubasteme::AST::BranchNode

Inherits:
Node
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubasteme/ast/branch_node.rb

Direct Known Subclasses

ListNode, ProgramNode, VectorNode

Instance Method Summary collapse

Methods inherited from Node

#to_s, #type

Constructor Details

#initialize(initial_size = nil) ⇒ BranchNode

Returns a new instance of BranchNode.



8
9
10
11
# File 'lib/rubasteme/ast/branch_node.rb', line 8

def initialize(initial_size = nil)
  super(nil)
  @nodes = initial_size.nil? ? [] : Array.new(initial_size)
end

Instance Method Details

#<<(node) ⇒ Object



40
41
42
# File 'lib/rubasteme/ast/branch_node.rb', line 40

def <<(node)
  @nodes << node
end

#[](index) ⇒ Object



32
33
34
# File 'lib/rubasteme/ast/branch_node.rb', line 32

def [](index)
  @nodes[index]
end

#[]=(index, node) ⇒ Object



36
37
38
# File 'lib/rubasteme/ast/branch_node.rb', line 36

def []=(index, node)
  @nodes[index] = node
end

#each(&blk) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/rubasteme/ast/branch_node.rb', line 23

def each(&blk)
  if block_given?
    @nodes.each(&blk)
    self
  else
    @nodes.each
  end
end

#sizeObject



13
14
15
# File 'lib/rubasteme/ast/branch_node.rb', line 13

def size
  @nodes.size
end

#to_aObject



17
18
19
# File 'lib/rubasteme/ast/branch_node.rb', line 17

def to_a
  [type].concat(@nodes.map(&:to_a))
end