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.



14518
14519
14520
14521
14522
14523
14524
14525
# File 'lib/prism/node.rb', line 14518

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)

attr_reader variable: LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode | MissingNode



14561
14562
14563
# File 'lib/prism/node.rb', line 14561

def variable
  @variable
end

Class Method Details

.typeObject

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



14592
14593
14594
# File 'lib/prism/node.rb', line 14592

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.



14598
14599
14600
14601
14602
# File 'lib/prism/node.rb', line 14598

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



14528
14529
14530
# File 'lib/prism/node.rb', line 14528

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



14533
14534
14535
# File 'lib/prism/node.rb', line 14533

def child_nodes
  [variable]
end

#comment_targetsObject

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



14543
14544
14545
# File 'lib/prism/node.rb', line 14543

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14538
14539
14540
# File 'lib/prism/node.rb', line 14538

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



14548
14549
14550
# File 'lib/prism/node.rb', line 14548

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 }



14556
14557
14558
# File 'lib/prism/node.rb', line 14556

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

#inspectObject

def inspect -> String



14582
14583
14584
# File 'lib/prism/node.rb', line 14582

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



14577
14578
14579
# File 'lib/prism/node.rb', line 14577

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



14564
14565
14566
14567
14568
# File 'lib/prism/node.rb', line 14564

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.



14572
14573
14574
# File 'lib/prism/node.rb', line 14572

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

#typeObject

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



14587
14588
14589
# File 'lib/prism/node.rb', line 14587

def type
  :pinned_variable_node
end