Class: Prism::PinnedVariableNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::PinnedVariableNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Represents the use of the ^ operator for pinning a variable in a pattern matching expression.
foo in ^bar
^^^^
Class Method Summary collapse
-
.type ⇒ :pinned_variable_node
See
Node.type.
Instance Method Summary collapse
-
#===(other) ⇒ boolish
: (untyped other) -> boolish.
-
#accept(visitor) ⇒ Object
See Node.accept.
-
#child_nodes ⇒ Array[node?]
(also: #deconstruct)
See Node.child_nodes.
-
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, variable: self.variable, operator_loc: self.operator_loc) ⇒ PinnedVariableNode
:call-seq: copy(**fields) -> PinnedVariableNode.
-
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped].
-
#each_child_node {|arg0| ... } ⇒ Object
See Node.each_child_node.
-
#initialize(source, node_id, location, flags, variable, operator_loc) ⇒ PinnedVariableNode
constructor
Initialize a new PinnedVariableNode node.
-
#inspect ⇒ String
: () -> String.
-
#operator ⇒ String
:call-seq: operator -> String.
-
#operator_loc ⇒ Location
:category: Locations :call-seq: operator_loc -> Location.
-
#save_operator_loc(repository) ⇒ Relocation::Entry
:category: Repository Save the operator_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :pinned_variable_node
See
Node#type. -
#variable ⇒ LocalVariableReadNode, ...
:call-seq: variable -> LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode.
Constructor Details
#initialize(source, node_id, location, flags, variable, operator_loc) ⇒ PinnedVariableNode
Initialize a new PinnedVariableNode node.
: (Source source, Integer node_id, Location location, Integer flags, (LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode) variable, Location operator_loc) -> void
26795 26796 26797 26798 26799 26800 26801 26802 |
# File 'lib/prism/node.rb', line 26795 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 |
Class Method Details
.type ⇒ :pinned_variable_node
See Node.type.
: () -> :pinned_variable_node
26883 26884 26885 |
# File 'lib/prism/node.rb', line 26883 def self.type :pinned_variable_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
26955 26956 26957 26958 26959 |
# File 'lib/prism/node.rb', line 26955 def ===(other) # :nodoc: other.is_a?(PinnedVariableNode) && (variable === other.variable) && (operator_loc.nil? == other.operator_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
26818 26819 26820 |
# File 'lib/prism/node.rb', line 26818 def accept(visitor) visitor.visit_pinned_variable_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
26825 26826 26827 |
# File 'lib/prism/node.rb', line 26825 def child_nodes [variable] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
26842 26843 26844 |
# File 'lib/prism/node.rb', line 26842 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) ⇒ PinnedVariableNode
:call-seq:
copy(**fields) -> PinnedVariableNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?variable: (LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode), ?operator_loc: Location) -> PinnedVariableNode
26852 26853 26854 |
# File 'lib/prism/node.rb', line 26852 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) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
26859 26860 26861 26862 26863 26864 26865 26866 26867 26868 26869 26870 26871 |
# File 'lib/prism/node.rb', line 26859 def deconstruct_keys(keys) # :nodoc: (keys || i[node_id location variable operator_loc operator]).each_with_object( {} #: Hash[Symbol, untyped] ) do |key, deconstructed| case key when :node_id then deconstructed[:node_id] = self.node_id when :location then deconstructed[:location] = self.location when :variable then deconstructed[:variable] = self.variable when :operator_loc then deconstructed[:operator_loc] = self.operator_loc when :operator then deconstructed[:operator] = self.operator end end end |
#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void
See Node.each_child_node.
: () -> Enumerator[node, void] : () { (node) -> void } -> void
26833 26834 26835 26836 26837 |
# File 'lib/prism/node.rb', line 26833 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield variable end |
#inspect ⇒ String
: () -> String
26888 26889 26890 |
# File 'lib/prism/node.rb', line 26888 def inspect # :nodoc: InspectVisitor.compose(self) end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
26948 26949 26950 |
# File 'lib/prism/node.rb', line 26948 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
The Location of the ^ operator
foo in ^bar
^
: () -> Location
26925 26926 26927 26928 26929 |
# File 'lib/prism/node.rb', line 26925 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) ⇒ Relocation::Entry
:category: Repository Save the operator_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry
26936 26937 26938 |
# File 'lib/prism/node.rb', line 26936 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#type ⇒ :pinned_variable_node
See Node#type.
: () -> :pinned_variable_node
26876 26877 26878 |
# File 'lib/prism/node.rb', line 26876 def type :pinned_variable_node end |
#variable ⇒ LocalVariableReadNode, ...
:call-seq:
variable -> LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode
The variable used in the pinned expression
foo in ^bar
^^^
: () -> (LocalVariableReadNode | InstanceVariableReadNode | ClassVariableReadNode | GlobalVariableReadNode | BackReferenceReadNode | NumberedReferenceReadNode | ItLocalVariableReadNode)
26907 26908 26909 |
# File 'lib/prism/node.rb', line 26907 def variable @variable end |