Class: SyntaxTree::PinnedVarRef
Overview
PinnedVarRef represents a pinned variable reference within a pattern matching pattern.
case value
in ^variable
end
This can be a plain local variable like the example above. It can also be a a class variable, a global variable, or an instance variable.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#value ⇒ Object
readonly
- Const | CVar | GVar | Ident | IVar
-
the value of this node.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(value: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:) ⇒ PinnedVarRef
constructor
A new instance of PinnedVarRef.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(value:, location:) ⇒ PinnedVarRef
Returns a new instance of PinnedVarRef.
11668 11669 11670 11671 11672 |
# File 'lib/syntax_tree/node.rb', line 11668 def initialize(value:, location:) @value = value @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11666 11667 11668 |
# File 'lib/syntax_tree/node.rb', line 11666 def comments @comments end |
#value ⇒ Object (readonly)
- Const | CVar | GVar | Ident | IVar
-
the value of this node
11663 11664 11665 |
# File 'lib/syntax_tree/node.rb', line 11663 def value @value end |
Instance Method Details
#===(other) ⇒ Object
11706 11707 11708 |
# File 'lib/syntax_tree/node.rb', line 11706 def ===(other) other.is_a?(PinnedVarRef) && value === other.value end |
#accept(visitor) ⇒ Object
11674 11675 11676 |
# File 'lib/syntax_tree/node.rb', line 11674 def accept(visitor) visitor.visit_pinned_var_ref(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11678 11679 11680 |
# File 'lib/syntax_tree/node.rb', line 11678 def child_nodes [value] end |
#copy(value: nil, location: nil) ⇒ Object
11682 11683 11684 11685 11686 11687 11688 11689 11690 11691 |
# File 'lib/syntax_tree/node.rb', line 11682 def copy(value: nil, location: nil) node = PinnedVarRef.new( value: value || self.value, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
11695 11696 11697 |
# File 'lib/syntax_tree/node.rb', line 11695 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
11699 11700 11701 11702 11703 11704 |
# File 'lib/syntax_tree/node.rb', line 11699 def format(q) q.group do q.text("^") q.format(value) end end |