Class: Parser::AST::Node
- Inherits:
-
Object
- Object
- Parser::AST::Node
- 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
-
#initialize(type, children = [], properties = {}) ⇒ Node
constructor
Initialize a Node.
-
#parent ⇒ Parser::AST::Node
Get the parent node.
-
#parent=(node) ⇒ Object
Set the parent node.
Methods included from ParserNodeExt
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
#parent ⇒ Parser::AST::Node
Get the parent node.
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.
26 27 28 |
# File 'lib/parser_node_ext/parent_node_ext.rb', line 26 def parent=(node) @mutable_attributes[:parent] = node end |