Class: Prism::PinnedVariableNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents the use of the ‘^` operator for pinning a variable in a pattern matching expression.

foo in ^bar
       ^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, variable, operator_loc) ⇒ PinnedVariableNode

Initialize a new PinnedVariableNode node.



14720
14721
14722
14723
14724
14725
14726
14727
# File 'lib/prism/node.rb', line 14720

def initialize(source, node_id, location, flags, variable, operator_loc)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @variable = variable
  @operator_loc = operator_loc
end

Instance Attribute Details

#variableObject (readonly)

The variable used in the pinned expression

foo in ^bar
        ^^^


14766
14767
14768
# File 'lib/prism/node.rb', line 14766

def variable
  @variable
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



14800
14801
14802
# File 'lib/prism/node.rb', line 14800

def self.type
  :pinned_variable_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



14806
14807
14808
14809
14810
# File 'lib/prism/node.rb', line 14806

def ===(other)
  other.is_a?(PinnedVariableNode) &&
    (variable === other.variable) &&
    (operator_loc.nil? == other.operator_loc.nil?)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



14730
14731
14732
# File 'lib/prism/node.rb', line 14730

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



14735
14736
14737
# File 'lib/prism/node.rb', line 14735

def child_nodes
  [variable]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



14745
14746
14747
# File 'lib/prism/node.rb', line 14745

def comment_targets
  [variable, operator_loc] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14740
14741
14742
# File 'lib/prism/node.rb', line 14740

def compact_child_nodes
  [variable]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, variable: self.variable, operator_loc: self.operator_loc) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?variable: LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode | MissingNode, ?operator_loc: Location) -> PinnedVariableNode



14750
14751
14752
# File 'lib/prism/node.rb', line 14750

def copy(node_id: self.node_id, location: self.location, flags: self.flags, variable: self.variable, operator_loc: self.operator_loc)
  PinnedVariableNode.new(source, node_id, location, flags, variable, operator_loc)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, variable: LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode | MissingNode, operator_loc: Location }



14758
14759
14760
# File 'lib/prism/node.rb', line 14758

def deconstruct_keys(keys)
  { node_id: node_id, location: location, variable: variable, operator_loc: operator_loc }
end

#inspectObject

def inspect -> String



14790
14791
14792
# File 'lib/prism/node.rb', line 14790

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



14785
14786
14787
# File 'lib/prism/node.rb', line 14785

def operator
  operator_loc.slice
end

#operator_locObject

The location of the ‘^` operator

foo in ^bar
       ^


14772
14773
14774
14775
14776
# File 'lib/prism/node.rb', line 14772

def operator_loc
  location = @operator_loc
  return location if location.is_a?(Location)
  @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#save_operator_loc(repository) ⇒ Object

Save the operator_loc location using the given saved source so that it can be retrieved later.



14780
14781
14782
# File 'lib/prism/node.rb', line 14780

def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



14795
14796
14797
# File 'lib/prism/node.rb', line 14795

def type
  :pinned_variable_node
end