Class: SyntaxTree::PinnedVarRef
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::PinnedVarRef
show all
- Defined in:
- lib/syntax_tree/node.rb
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
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(value:, location:) ⇒ PinnedVarRef
11526
11527
11528
11529
11530
|
# File 'lib/syntax_tree/node.rb', line 11526
def initialize(value:, location:)
@value = value
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11524
11525
11526
|
# File 'lib/syntax_tree/node.rb', line 11524
def
end
|
#value ⇒ Object
- VarRef
-
the value of this node
11521
11522
11523
|
# File 'lib/syntax_tree/node.rb', line 11521
def value
@value
end
|
Instance Method Details
#===(other) ⇒ Object
11564
11565
11566
|
# File 'lib/syntax_tree/node.rb', line 11564
def ===(other)
other.is_a?(PinnedVarRef) && value === other.value
end
|
#accept(visitor) ⇒ Object
11532
11533
11534
|
# File 'lib/syntax_tree/node.rb', line 11532
def accept(visitor)
visitor.visit_pinned_var_ref(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
11536
11537
11538
|
# File 'lib/syntax_tree/node.rb', line 11536
def child_nodes
[value]
end
|
#copy(value: nil, location: nil) ⇒ Object
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
|
# File 'lib/syntax_tree/node.rb', line 11540
def copy(value: nil, location: nil)
node =
PinnedVarRef.new(
value: value || self.value,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
11553
11554
11555
|
# File 'lib/syntax_tree/node.rb', line 11553
def deconstruct_keys(_keys)
{ value: value, location: location, comments: }
end
|
11557
11558
11559
11560
11561
11562
|
# File 'lib/syntax_tree/node.rb', line 11557
def format(q)
q.group do
q.text("^")
q.format(value)
end
end
|