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.


13103
13104
13105
13106
13107
13108
13109
13110
# File 'lib/prism/node.rb', line 13103

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


13146
13147
13148
# File 'lib/prism/node.rb', line 13146

def variable
  @variable
end

Class Method Details

.typeObject

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


13171
13172
13173
# File 'lib/prism/node.rb', line 13171

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.


13177
13178
13179
13180
13181
# File 'lib/prism/node.rb', line 13177

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


13113
13114
13115
# File 'lib/prism/node.rb', line 13113

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

#child_nodesObject Also known as: deconstruct

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


13118
13119
13120
# File 'lib/prism/node.rb', line 13118

def child_nodes
  [variable]
end

#comment_targetsObject

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


13128
13129
13130
# File 'lib/prism/node.rb', line 13128

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array


13123
13124
13125
# File 'lib/prism/node.rb', line 13123

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


13133
13134
13135
# File 'lib/prism/node.rb', line 13133

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 }


13141
13142
13143
# File 'lib/prism/node.rb', line 13141

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

#inspectObject

def inspect -> String


13161
13162
13163
# File 'lib/prism/node.rb', line 13161

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String


13156
13157
13158
# File 'lib/prism/node.rb', line 13156

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location


13149
13150
13151
13152
13153
# File 'lib/prism/node.rb', line 13149

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

#typeObject

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


13166
13167
13168
# File 'lib/prism/node.rb', line 13166

def type
  :pinned_variable_node
end