Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/synvert/core/array_ext.rb
Overview
Extend Array.
Instance Method Summary collapse
-
#child_node_by_name(child_name) ⇒ Parser::AST::Node
Get child node by the name.
-
#child_node_range(child_name) ⇒ Parser::Source::Range
Get the source range of child node.
Instance Method Details
#child_node_by_name(child_name) ⇒ Parser::AST::Node
Get child node by the name.
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 |
#child_node_range(child_name) ⇒ Parser::Source::Range
Get the source range of child node.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/synvert/core/array_ext.rb', line 23 def child_node_range(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) if nested_child_name return child_direct_child_node.child_node_range(nested_child_name) elsif child_direct_child_node return ( Parser::Source::Range.new( '(string)', child_direct_child_node.loc.expression.begin_pos, child_direct_child_node.loc.expression.end_pos ) ) else raise Synvert::Core::MethodNotSupported, "child_node_range is not handled for #{map(&:debug_info).join("\n")}, child_name: #{child_name}" end end |