Class: Yoda::AST::Vnode
Abstract
Overview
Defined Under Namespace
Modules: CommentAssociation, CommentPositional, Positional
Instance Attribute Summary collapse
Instance Method Summary
collapse
#comments_by_vnode, #positionally_nearest_comment, #positionally_nearest_commenting_node
Methods included from Positional
#location, #positionally_include?, #positionally_nearest_child, #range, #source_map
#all_nodes_lazy, #associate_comments, #comments, #wrapping?
#query, #query_all, #query_ancestor, #query_ancestors
#calc_current_location_method, #including_method, #method?
#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
=
end
|
Instance Attribute Details
13
14
15
|
# File 'lib/yoda/ast/vnode.rb', line 13
def
end
|
#parent ⇒ Vnode?
10
11
12
|
# File 'lib/yoda/ast/vnode.rb', line 10
def parent
@parent
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
|
#wrap_child(child_node) ⇒ Vnode
29
30
31
|
# File 'lib/yoda/ast/vnode.rb', line 29
def wrap_child(child_node)
AST.wrap(child_node, parent: self, comments_by_node: )
end
|