Class: Parser::AST::Node

Inherits:
Object
  • Object
show all
Includes:
ParserNodeExt
Defined in:
lib/parser_node_ext.rb,
lib/parser_node_ext/parent_node_ext.rb

Overview

Extend Parser::AST::Node.

Constant Summary

Constants included from ParserNodeExt

ParserNodeExt::TYPE_CHILDREN, ParserNodeExt::VERSION

Instance Method Summary collapse

Methods included from ParserNodeExt

included

Constructor Details

#initialize(type, children = [], properties = {}) ⇒ Node

Initialize a Node.

It extends Parser::AST::Node and set parent for its child nodes.



7
8
9
10
11
12
13
14
15
16
# File 'lib/parser_node_ext/parent_node_ext.rb', line 7

def initialize(type, children = [], properties = {})
  @mutable_attributes = {}
  super
  # children could be nil for s(:array)
  Array(children).each do |child_node|
    if child_node.is_a?(Parser::AST::Node)
      child_node.parent = self
    end
  end
end

Instance Method Details

#parentParser::AST::Node

Get the parent node.

Returns:



20
21
22
# File 'lib/parser_node_ext/parent_node_ext.rb', line 20

def parent
  @mutable_attributes[:parent]
end

#parent=(node) ⇒ Object

Set the parent node.

Parameters:



26
27
28
# File 'lib/parser_node_ext/parent_node_ext.rb', line 26

def parent=(node)
  @mutable_attributes[:parent] = node
end