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.



13066
13067
13068
13069
13070
13071
13072
13073
# File 'lib/prism/node.rb', line 13066

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: Prism::node



13109
13110
13111
# File 'lib/prism/node.rb', line 13109

def variable
  @variable
end

Class Method Details

.typeObject

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



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

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.



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

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



13076
13077
13078
# File 'lib/prism/node.rb', line 13076

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

#child_nodesObject Also known as: deconstruct

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



13081
13082
13083
# File 'lib/prism/node.rb', line 13081

def child_nodes
  [variable]
end

#comment_targetsObject

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



13091
13092
13093
# File 'lib/prism/node.rb', line 13091

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



13086
13087
13088
# File 'lib/prism/node.rb', line 13086

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: Prism::node, ?operator_loc: Location) -> PinnedVariableNode



13096
13097
13098
# File 'lib/prism/node.rb', line 13096

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: Prism::node, operator_loc: Location }



13104
13105
13106
# File 'lib/prism/node.rb', line 13104

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

#inspectObject

def inspect -> String



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

def inspect
  InspectVisitor.compose(self)
end

#operatorObject

def operator: () -> String



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

def operator
  operator_loc.slice
end

#operator_locObject

attr_reader operator_loc: Location



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

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`.



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

def type
  :pinned_variable_node
end