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.
11651 11652 11653 11654 11655 |
# File 'lib/syntax_tree/node.rb', line 11651 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
11649 11650 11651 |
# File 'lib/syntax_tree/node.rb', line 11649 def comments @comments end |
#value ⇒ Object (readonly)
- Const | CVar | GVar | Ident | IVar
-
the value of this node
11646 11647 11648 |
# File 'lib/syntax_tree/node.rb', line 11646 def value @value end |
Instance Method Details
#===(other) ⇒ Object
11689 11690 11691 |
# File 'lib/syntax_tree/node.rb', line 11689 def ===(other) other.is_a?(PinnedVarRef) && value === other.value end |
#accept(visitor) ⇒ Object
11657 11658 11659 |
# File 'lib/syntax_tree/node.rb', line 11657 def accept(visitor) visitor.visit_pinned_var_ref(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11661 11662 11663 |
# File 'lib/syntax_tree/node.rb', line 11661 def child_nodes [value] end |
#copy(value: nil, location: nil) ⇒ Object
11665 11666 11667 11668 11669 11670 11671 11672 11673 11674 |
# File 'lib/syntax_tree/node.rb', line 11665 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
11678 11679 11680 |
# File 'lib/syntax_tree/node.rb', line 11678 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
11682 11683 11684 11685 11686 11687 |
# File 'lib/syntax_tree/node.rb', line 11682 def format(q) q.group do q.text("^") q.format(value) end end |