Class: Transpec::AST::Node
- Inherits:
-
Parser::AST::Node
- Object
- Parser::AST::Node
- Transpec::AST::Node
- Defined in:
- lib/transpec/ast/node.rb
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.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/transpec/ast/node.rb', line 10 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.
8 9 10 |
# File 'lib/transpec/ast/node.rb', line 8 def @metadata end |
Instance Method Details
#ancestor_nodes ⇒ Object
43 44 45 |
# File 'lib/transpec/ast/node.rb', line 43 def ancestor_nodes each_ancestor_node.to_a end |
#child_nodes ⇒ Object
58 59 60 |
# File 'lib/transpec/ast/node.rb', line 58 def child_nodes each_child_node.to_a end |
#descendent_nodes ⇒ Object
71 72 73 |
# File 'lib/transpec/ast/node.rb', line 71 def descendent_nodes each_descendent_node.to_a end |
#each_ancestor_node(&block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/transpec/ast/node.rb', line 32 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
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/transpec/ast/node.rb', line 47 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
62 63 64 65 66 67 68 69 |
# File 'lib/transpec/ast/node.rb', line 62 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
75 76 77 78 79 |
# File 'lib/transpec/ast/node.rb', line 75 def each_node(&block) return to_enum(__method__) unless block_given? yield self each_descendent_node(&block) end |
#parent_node ⇒ Object
22 23 24 |
# File 'lib/transpec/ast/node.rb', line 22 def parent_node @mutable_attributes[:parent_node] end |