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

#pretty_print, #to_json

Constructor Details

#initialize(value:, location:, comments: []) ⇒ PinnedVarRef

Returns a new instance of PinnedVarRef.



8738
8739
8740
8741
8742
# File 'lib/syntax_tree/node.rb', line 8738

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



8736
8737
8738
# File 'lib/syntax_tree/node.rb', line 8736

def comments
  @comments
end

#valueObject (readonly)

VarRef

the value of this node



8733
8734
8735
# File 'lib/syntax_tree/node.rb', line 8733

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



8744
8745
8746
# File 'lib/syntax_tree/node.rb', line 8744

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

#child_nodesObject Also known as: deconstruct



8748
8749
8750
# File 'lib/syntax_tree/node.rb', line 8748

def child_nodes
  [value]
end

#deconstruct_keys(keys) ⇒ Object



8754
8755
8756
# File 'lib/syntax_tree/node.rb', line 8754

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

#format(q) ⇒ Object



8758
8759
8760
8761
8762
8763
# File 'lib/syntax_tree/node.rb', line 8758

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