Class: Transpec::AST::Node
- Inherits:
-
Parser::AST::Node
- Object
- Parser::AST::Node
- Transpec::AST::Node
- Defined in:
- lib/transpec/ast/node.rb
Constant Summary collapse
- TYPES =
%w( true false nil int float str dstr sym dsym xstr regexp regopt array splat hash pair kwsplat irange erange self lvar ivar cvar gvar nth_ref back_ref const cbase defined? lvasgn ivasgn cvasgn gvasgn casgn masgn mlhs op_asgn or_asgn and_asgn module class sclass def defs undef alias args arg optarg restarg blockarg shadowarg kwarg kwoptarg kwrestarg send super zsuper yield block block_pass and or not if case when while until while_post until_post for break next redo return begin rescue resbody ensure retry preexe postexe iflipflop eflipflop match_current_line match_with_lvasgn ).map(&:to_sym).freeze
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #ancestor_nodes ⇒ Object
- #child_nodes ⇒ Object
- #descendent_nodes ⇒ Object
- #each_ancestor_node(&block) ⇒ Object
- #each_child_node ⇒ Object
- #each_descendent_node(&block) ⇒ Object
- #each_node {|_self| ... } ⇒ Object
-
#initialize(type, children = [], properties = {}) ⇒ Node
constructor
A new instance of Node.
- #parent_node ⇒ Object
Constructor Details
#initialize(type, children = [], properties = {}) ⇒ Node
Returns a new instance of Node.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/transpec/ast/node.rb', line 50 def initialize(type, children = [], properties = {}) @metadata = {} @mutable_attributes = {} # ::AST::Node#initialize freezes itself. super each_child_node do |child_node| child_node.parent_node = self end end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
48 49 50 |
# File 'lib/transpec/ast/node.rb', line 48 def @metadata end |
Instance Method Details
#ancestor_nodes ⇒ Object
90 91 92 |
# File 'lib/transpec/ast/node.rb', line 90 def ancestor_nodes each_ancestor_node.to_a end |
#child_nodes ⇒ Object
105 106 107 |
# File 'lib/transpec/ast/node.rb', line 105 def child_nodes each_child_node.to_a end |
#descendent_nodes ⇒ Object
118 119 120 |
# File 'lib/transpec/ast/node.rb', line 118 def descendent_nodes each_descendent_node.to_a end |
#each_ancestor_node(&block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/transpec/ast/node.rb', line 79 def each_ancestor_node(&block) return to_enum(__method__) unless block_given? if parent_node yield parent_node parent_node.each_ancestor_node(&block) end self end |
#each_child_node ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/transpec/ast/node.rb', line 94 def each_child_node return to_enum(__method__) unless block_given? children.each do |child| next unless child.is_a?(self.class) yield child end self end |
#each_descendent_node(&block) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/transpec/ast/node.rb', line 109 def each_descendent_node(&block) return to_enum(__method__) unless block_given? each_child_node do |child_node| yield child_node child_node.each_descendent_node(&block) end end |
#each_node {|_self| ... } ⇒ Object
122 123 124 125 126 |
# File 'lib/transpec/ast/node.rb', line 122 def each_node(&block) return to_enum(__method__) unless block_given? yield self each_descendent_node(&block) end |
#parent_node ⇒ Object
69 70 71 |
# File 'lib/transpec/ast/node.rb', line 69 def parent_node @mutable_attributes[:parent_node] end |