Method: Array#child_node_by_name

Defined in:
lib/synvert/core/array_ext.rb

#child_node_by_name(child_name) ⇒ Parser::AST::Node

Get child node by the name.

Parameters:

  • child_name (String)

    name of child node.

Returns:

Raises:



9
10
11
12
13
14
15
16
17
# File 'lib/synvert/core/array_ext.rb', line 9

def child_node_by_name(child_name)
  direct_child_name, nested_child_name = child_name.split('.', 2)
  child_direct_child_node = direct_child_name =~ /\A\d+\z/ ? self[direct_child_name.to_i - 1] : self.send(direct_child_name)
  return child_direct_child_node.child_node_by_name(nested_child_name) if nested_child_name
  return child_direct_child_node if child_direct_child_node

  raise Synvert::Core::MethodNotSupported,
        "child_node_by_name is not handled for #{map(&:debug_info).join("\n")}, child_name: #{child_name}"
end