Class: Transpec::AST::Node

Inherits:
Parser::AST::Node
  • Object
show all
Defined in:
lib/transpec/ast/node.rb

Instance Method Summary collapse

Instance Method Details

#child_nodesObject



19
20
21
# File 'lib/transpec/ast/node.rb', line 19

def child_nodes
  each_child_node.to_a
end

#descendent_nodesObject



32
33
34
# File 'lib/transpec/ast/node.rb', line 32

def descendent_nodes
  each_descendent_node.to_a
end

#each_child_nodeObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/transpec/ast/node.rb', line 8

def each_child_node
  return to_enum(__method__) unless block_given?

  children.each do |child|
    next unless child.is_a?(self.class)
    yield child
  end

  self
end

#each_descendent_node(&block) ⇒ Object



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

def each_descendent_node(&block)
  return to_enum(__method__) unless block_given?

  each_child_node do |child_node|
    yield child_node
    child_node.each_child_node(&block)
  end
end