Class: Prism::CapturePatternNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::CapturePatternNode
- Defined in:
- lib/prism/node.rb,
sig/generated/prism/node.rbs,
ext/prism/api_node.c
Overview
Represents assigning to a local variable in pattern matching.
foo => [bar => baz]
^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :capture_pattern_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, value: self.value, target: self.target, operator_loc: self.operator_loc) ⇒ CapturePatternNode
:call-seq: copy(**fields) -> CapturePatternNode.
-
#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, value, target, operator_loc) ⇒ CapturePatternNode
constructor
Initialize a new CapturePatternNode 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.
-
#target ⇒ LocalVariableTargetNode
:call-seq: target -> LocalVariableTargetNode.
-
#type ⇒ :capture_pattern_node
See
Node#type. -
#value ⇒ Prism::node
:call-seq: value -> Node.
Constructor Details
#initialize(source, node_id, location, flags, value, target, operator_loc) ⇒ CapturePatternNode
Initialize a new CapturePatternNode node.
: (Source source, Integer node_id, Location location, Integer flags, Prism::node value, LocalVariableTargetNode target, Location operator_loc) -> void
6120 6121 6122 6123 6124 6125 6126 6127 6128 |
# File 'lib/prism/node.rb', line 6120 def initialize(source, node_id, location, flags, value, target, operator_loc) @source = source @node_id = node_id @location = location @flags = flags @value = value @target = target @operator_loc = operator_loc end |
Class Method Details
.type ⇒ :capture_pattern_node
See Node.type.
: () -> :capture_pattern_node
6211 6212 6213 |
# File 'lib/prism/node.rb', line 6211 def self.type :capture_pattern_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
6300 6301 6302 6303 6304 6305 |
# File 'lib/prism/node.rb', line 6300 def ===(other) # :nodoc: other.is_a?(CapturePatternNode) && (value === other.value) && (target === other.target) && (operator_loc.nil? == other.operator_loc.nil?) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
6144 6145 6146 |
# File 'lib/prism/node.rb', line 6144 def accept(visitor) visitor.visit_capture_pattern_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
6151 6152 6153 |
# File 'lib/prism/node.rb', line 6151 def child_nodes [value, target] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
6169 6170 6171 |
# File 'lib/prism/node.rb', line 6169 def compact_child_nodes [value, target] end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, target: self.target, operator_loc: self.operator_loc) ⇒ CapturePatternNode
:call-seq:
copy(**fields) -> CapturePatternNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?value: Prism::node, ?target: LocalVariableTargetNode, ?operator_loc: Location) -> CapturePatternNode
6179 6180 6181 |
# File 'lib/prism/node.rb', line 6179 def copy(node_id: self.node_id, location: self.location, flags: self.flags, value: self.value, target: self.target, operator_loc: self.operator_loc) CapturePatternNode.new(source, node_id, location, flags, value, target, operator_loc) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 |
# File 'lib/prism/node.rb', line 6186 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location value target 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 :value then deconstructed[:value] = self.value when :target then deconstructed[:target] = self.target 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
6159 6160 6161 6162 6163 6164 |
# File 'lib/prism/node.rb', line 6159 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? yield value yield target end |
#inspect ⇒ String
: () -> String
6216 6217 6218 |
# File 'lib/prism/node.rb', line 6216 def inspect # :nodoc: InspectVisitor.compose(self) end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
6293 6294 6295 |
# File 'lib/prism/node.rb', line 6293 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
Represents the Location of the => operator.
foo => bar
^^
: () -> Location
6270 6271 6272 6273 6274 |
# File 'lib/prism/node.rb', line 6270 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
6281 6282 6283 |
# File 'lib/prism/node.rb', line 6281 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#target ⇒ LocalVariableTargetNode
:call-seq:
target -> LocalVariableTargetNode
Represents the target of the capture.
foo => bar
^^^
: () -> LocalVariableTargetNode
6252 6253 6254 |
# File 'lib/prism/node.rb', line 6252 def target @target end |
#type ⇒ :capture_pattern_node
See Node#type.
: () -> :capture_pattern_node
6204 6205 6206 |
# File 'lib/prism/node.rb', line 6204 def type :capture_pattern_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
Represents the value to capture.
foo => bar
^^^
: () -> Prism::node
6235 6236 6237 |
# File 'lib/prism/node.rb', line 6235 def value @value end |