Module: ASTUtils::NodeHelper

Included in:
Labeling, Navigation, Scope
Defined in:
lib/ast_utils/node_helper.rb

Instance Method Summary collapse

Instance Method Details

#each_child_node(node) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/ast_utils/node_helper.rb', line 3

def each_child_node(node)
  if block_given?
    node.children.each do |child|
      if child.is_a?(AST::Node)
        yield child
      end
    end
  else
    enum_for :each_child_node, node
  end
end

#map_child_node(node) ⇒ Object

order preserved



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ast_utils/node_helper.rb', line 16

def map_child_node(node)
  if block_given?
    node.children.each.with_object([]) do |child, array|
      if child.is_a?(AST::Node)
        array << yield(child)
      else
        array << child
      end
    end
  else
    enum_for :map_child_node, node
  end
end