Class: SyntaxTree::PinnedVarRef

Inherits:
Node
  • Object
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:, comments: []) ⇒ PinnedVarRef

Returns a new instance of PinnedVarRef.



9537
9538
9539
9540
9541
# File 'lib/syntax_tree/node.rb', line 9537

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9535
9536
9537
# File 'lib/syntax_tree/node.rb', line 9535

def comments
  @comments
end

#valueObject (readonly)

VarRef

the value of this node



9532
9533
9534
# File 'lib/syntax_tree/node.rb', line 9532

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



9543
9544
9545
# File 'lib/syntax_tree/node.rb', line 9543

def accept(visitor)
  visitor.visit_pinned_var_ref(self)
end

#child_nodesObject Also known as: deconstruct



9547
9548
9549
# File 'lib/syntax_tree/node.rb', line 9547

def child_nodes
  [value]
end

#deconstruct_keys(_keys) ⇒ Object



9553
9554
9555
# File 'lib/syntax_tree/node.rb', line 9553

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



9557
9558
9559
9560
9561
9562
# File 'lib/syntax_tree/node.rb', line 9557

def format(q)
  q.group do
    q.text("^")
    q.format(value)
  end
end