Class: Yoda::AST::Vnode Abstract
- Inherits:
-
Object
- Object
- Yoda::AST::Vnode
- Includes:
- MethodTraversable, NamespaceTraversable, Traversable, CommentAssociation, CommentPositional, Positional
- Defined in:
- lib/yoda/ast/vnode.rb
Overview
This class is abstract.
Direct Known Subclasses
Defined Under Namespace
Modules: CommentAssociation, CommentPositional, Positional
Instance Attribute Summary collapse
- #comments_by_node ⇒ Hash{Parser::AST::Node => Array<Parser::Source::Comment>} readonly
- #parent ⇒ Vnode? readonly
Instance Method Summary collapse
- #children ⇒ Array<Vnode>
- #constant? ⇒ Boolean
- #empty? ⇒ boolean
- #identifier ⇒ String
-
#initialize(parent: nil, comments_by_node: {}) ⇒ Vnode
constructor
A new instance of Vnode.
- #inspect ⇒ String
- #inspect_content ⇒ String
-
#nesting ⇒ Array<Vnode>
All nodes between root and self.
- #present? ⇒ boolean
- #try(method_name, *args) ⇒ Object
- #type ⇒ Symbol
- #wrap_child(child_node) ⇒ Vnode
Methods included from CommentPositional
#comments_by_vnode, #positionally_nearest_comment, #positionally_nearest_commenting_node
Methods included from Positional
#location, #positionally_include?, #positionally_nearest_child, #range, #source_map
Methods included from CommentAssociation
#all_nodes_lazy, #associate_comments, #comments, #wrapping?
Methods included from Traversable
#query, #query_all, #query_ancestor, #query_ancestors
Methods included from MethodTraversable
#calc_current_location_method, #including_method, #method?
Methods included from NamespaceTraversable
#calc_current_location_namespace, #full_name, #namespace, #namespace?, #namespace_path, #root?
Constructor Details
#initialize(parent: nil, comments_by_node: {}) ⇒ Vnode
Returns a new instance of Vnode.
17 18 19 20 |
# File 'lib/yoda/ast/vnode.rb', line 17 def initialize(parent: nil, comments_by_node: {}) @parent = parent @comments_by_node = comments_by_node end |
Instance Attribute Details
#comments_by_node ⇒ Hash{Parser::AST::Node => Array<Parser::Source::Comment>} (readonly)
13 14 15 |
# File 'lib/yoda/ast/vnode.rb', line 13 def comments_by_node @comments_by_node end |
Instance Method Details
#children ⇒ Array<Vnode>
34 35 36 |
# File 'lib/yoda/ast/vnode.rb', line 34 def children fail NotImplementedError end |
#constant? ⇒ Boolean
48 49 50 |
# File 'lib/yoda/ast/vnode.rb', line 48 def constant? false end |
#empty? ⇒ boolean
39 40 41 |
# File 'lib/yoda/ast/vnode.rb', line 39 def empty? false end |
#identifier ⇒ String
58 59 60 |
# File 'lib/yoda/ast/vnode.rb', line 58 def identifier "#{type}:#{object_id}" end |
#inspect ⇒ String
63 64 65 |
# File 'lib/yoda/ast/vnode.rb', line 63 def inspect "(#{[identifier, inspect_content].join(' ')})" end |
#inspect_content ⇒ String
68 69 70 |
# File 'lib/yoda/ast/vnode.rb', line 68 def inspect_content children.map(&:inspect).join(' ') end |
#nesting ⇒ Array<Vnode>
Returns all nodes between root and self.
23 24 25 |
# File 'lib/yoda/ast/vnode.rb', line 23 def nesting @nesting ||= (parent&.nesting || []) + [self] end |
#present? ⇒ boolean
44 45 46 |
# File 'lib/yoda/ast/vnode.rb', line 44 def present? !empty? end |
#try(method_name, *args) ⇒ Object
72 73 74 |
# File 'lib/yoda/ast/vnode.rb', line 72 def try(method_name, *args) respond_to?(method_name) ? send(method_name, *args) : nil end |
#type ⇒ Symbol
53 54 55 |
# File 'lib/yoda/ast/vnode.rb', line 53 def type fail NotImplementedError end |