Class: Prism::PinnedVariableNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::PinnedVariableNode
- 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
-
#variable ⇒ Object
readonly
attr_reader variable: LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode | MissingNode.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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.
-
#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 }.
-
#initialize(source, node_id, location, flags, variable, operator_loc) ⇒ PinnedVariableNode
constructor
Initialize a new PinnedVariableNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#operator ⇒ Object
def operator: () -> String.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location.
-
#save_operator_loc(repository) ⇒ Object
Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, variable, operator_loc) ⇒ PinnedVariableNode
Initialize a new PinnedVariableNode node.
14512 14513 14514 14515 14516 14517 14518 14519 |
# File 'lib/prism/node.rb', line 14512 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
#variable ⇒ Object (readonly)
attr_reader variable: LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode | MissingNode
14555 14556 14557 |
# File 'lib/prism/node.rb', line 14555 def variable @variable end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
14586 14587 14588 |
# File 'lib/prism/node.rb', line 14586 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.
14592 14593 14594 14595 14596 |
# File 'lib/prism/node.rb', line 14592 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
14522 14523 14524 |
# File 'lib/prism/node.rb', line 14522 def accept(visitor) visitor.visit_pinned_variable_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
14527 14528 14529 |
# File 'lib/prism/node.rb', line 14527 def child_nodes [variable] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
14537 14538 14539 |
# File 'lib/prism/node.rb', line 14537 def comment_targets [variable, operator_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
14532 14533 14534 |
# File 'lib/prism/node.rb', line 14532 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
14542 14543 14544 |
# File 'lib/prism/node.rb', line 14542 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 }
14550 14551 14552 |
# File 'lib/prism/node.rb', line 14550 def deconstruct_keys(keys) { node_id: node_id, location: location, variable: variable, operator_loc: operator_loc } end |
#inspect ⇒ Object
def inspect -> String
14576 14577 14578 |
# File 'lib/prism/node.rb', line 14576 def inspect InspectVisitor.compose(self) end |
#operator ⇒ Object
def operator: () -> String
14571 14572 14573 |
# File 'lib/prism/node.rb', line 14571 def operator operator_loc.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location
14558 14559 14560 14561 14562 |
# File 'lib/prism/node.rb', line 14558 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.
14566 14567 14568 |
# File 'lib/prism/node.rb', line 14566 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
14581 14582 14583 |
# File 'lib/prism/node.rb', line 14581 def type :pinned_variable_node end |