Class: Prism::MultiWriteNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::MultiWriteNode
- Defined in:
- lib/prism/node.rb,
lib/prism/parse_result/newlines.rb,
sig/generated/prism/node.rbs,
sig/generated/prism/parse_result/newlines.rbs,
ext/prism/api_node.c
Overview
Represents a write to a multi-target expression.
a, b, c = 1, 2, 3
^^^^^^^^^^^^^^^^^
Class Method Summary collapse
-
.type ⇒ :multi_write_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, lefts: self.lefts, rest: self.rest, rights: self.rights, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc, operator_loc: self.operator_loc, value: self.value) ⇒ MultiWriteNode
:call-seq: copy(**fields) -> MultiWriteNode.
-
#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, lefts, rest, rights, lparen_loc, rparen_loc, operator_loc, value) ⇒ MultiWriteNode
constructor
Initialize a new MultiWriteNode node.
-
#inspect ⇒ String
: () -> String.
-
#lefts ⇒ Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode]
:call-seq: lefts -> Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode].
-
#lparen ⇒ String?
:call-seq: lparen -> String | nil.
-
#lparen_loc ⇒ Location?
:category: Locations :call-seq: lparen_loc -> Location | nil.
-
#newline_flag!(lines) ⇒ void
: (Array lines) -> void.
-
#operator ⇒ String
:call-seq: operator -> String.
-
#operator_loc ⇒ Location
:category: Locations :call-seq: operator_loc -> Location.
-
#rest ⇒ ImplicitRestNode, ...
:call-seq: rest -> ImplicitRestNode | SplatNode | nil.
-
#rights ⇒ Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode]
:call-seq: rights -> Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode].
-
#rparen ⇒ String?
:call-seq: rparen -> String | nil.
-
#rparen_loc ⇒ Location?
:category: Locations :call-seq: rparen_loc -> Location | nil.
-
#save_lparen_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the lparen_loc location using the given saved source so that it can be retrieved later.
-
#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.
-
#save_rparen_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the rparen_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ :multi_write_node
See
Node#type. -
#value ⇒ Prism::node
:call-seq: value -> Node.
Constructor Details
#initialize(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc, operator_loc, value) ⇒ MultiWriteNode
Initialize a new MultiWriteNode node.
: (Source source, Integer node_id, Location location, Integer flags, Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode] lefts, (ImplicitRestNode | SplatNode)? rest, Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode] rights, Location? lparen_loc, Location? rparen_loc, Location operator_loc, Prism::node value) -> void
24153 24154 24155 24156 24157 24158 24159 24160 24161 24162 24163 24164 24165 |
# File 'lib/prism/node.rb', line 24153 def initialize(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc, operator_loc, value) @source = source @node_id = node_id @location = location @flags = flags @lefts = lefts @rest = rest @rights = rights @lparen_loc = lparen_loc @rparen_loc = rparen_loc @operator_loc = operator_loc @value = value end |
Class Method Details
.type ⇒ :multi_write_node
See Node.type.
: () -> :multi_write_node
24261 24262 24263 |
# File 'lib/prism/node.rb', line 24261 def self.type :multi_write_node end |
Instance Method Details
#===(other) ⇒ boolish
: (untyped other) -> boolish
24499 24500 24501 24502 24503 24504 24505 24506 24507 24508 24509 24510 |
# File 'lib/prism/node.rb', line 24499 def ===(other) # :nodoc: other.is_a?(MultiWriteNode) && (lefts.length == other.lefts.length) && lefts.zip(other.lefts).all? { |left, right| left === right } && (rest === other.rest) && (rights.length == other.rights.length) && rights.zip(other.rights).all? { |left, right| left === right } && (lparen_loc.nil? == other.lparen_loc.nil?) && (rparen_loc.nil? == other.rparen_loc.nil?) && (operator_loc.nil? == other.operator_loc.nil?) && (value === other.value) end |
#accept(visitor) ⇒ Object
See Node.accept.
: (_Visitor visitor) -> untyped
24181 24182 24183 |
# File 'lib/prism/node.rb', line 24181 def accept(visitor) visitor.visit_multi_write_node(self) end |
#child_nodes ⇒ Array[node?] Also known as: deconstruct
See Node.child_nodes.
: () -> Array
24188 24189 24190 |
# File 'lib/prism/node.rb', line 24188 def child_nodes [*lefts, rest, *rights, value] end |
#compact_child_nodes ⇒ Array[node]
See Node.compact_child_nodes.
: () -> Array
24208 24209 24210 24211 24212 24213 24214 24215 |
# File 'lib/prism/node.rb', line 24208 def compact_child_nodes compact = [] #: Array[Prism::node] compact.concat(lefts) if (rest = self.rest); compact << rest; end compact.concat(rights) compact << value compact end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, lefts: self.lefts, rest: self.rest, rights: self.rights, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc, operator_loc: self.operator_loc, value: self.value) ⇒ MultiWriteNode
:call-seq:
copy(**fields) -> MultiWriteNode
Creates a copy of self with the given fields, using self as the template.
: (?node_id: Integer, ?location: Location, ?flags: Integer, ?lefts: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode], ?rest: (ImplicitRestNode | SplatNode)?, ?rights: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode], ?lparen_loc: Location?, ?rparen_loc: Location?, ?operator_loc: Location, ?value: Prism::node) -> MultiWriteNode
24223 24224 24225 |
# File 'lib/prism/node.rb', line 24223 def copy(node_id: self.node_id, location: self.location, flags: self.flags, lefts: self.lefts, rest: self.rest, rights: self.rights, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc, operator_loc: self.operator_loc, value: self.value) MultiWriteNode.new(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc, operator_loc, value) end |
#deconstruct_keys(keys) ⇒ Hash[Symbol, untyped]
: (Array? keys) -> Hash[Symbol, untyped]
24230 24231 24232 24233 24234 24235 24236 24237 24238 24239 24240 24241 24242 24243 24244 24245 24246 24247 24248 24249 |
# File 'lib/prism/node.rb', line 24230 def deconstruct_keys(keys) # :nodoc: (keys || %i[node_id location lefts rest rights lparen_loc rparen_loc operator_loc value lparen rparen 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 :lefts then deconstructed[:lefts] = self.lefts when :rest then deconstructed[:rest] = self.rest when :rights then deconstructed[:rights] = self.rights when :lparen_loc then deconstructed[:lparen_loc] = self.lparen_loc when :rparen_loc then deconstructed[:rparen_loc] = self.rparen_loc when :operator_loc then deconstructed[:operator_loc] = self.operator_loc when :value then deconstructed[:value] = self.value when :lparen then deconstructed[:lparen] = self.lparen when :rparen then deconstructed[:rparen] = self.rparen 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
24196 24197 24198 24199 24200 24201 24202 24203 |
# File 'lib/prism/node.rb', line 24196 def each_child_node(&blk) return to_enum(:each_child_node) unless block_given? lefts.each { |node| yield node } if (rest = self.rest); yield rest; end rights.each { |node| yield node } yield value end |
#inspect ⇒ String
: () -> String
24266 24267 24268 |
# File 'lib/prism/node.rb', line 24266 def inspect # :nodoc: InspectVisitor.compose(self) end |
#lefts ⇒ Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode]
:call-seq:
lefts -> Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode]
Represents the targets expressions before a splat node.
a, b, * = 1, 2, 3, 4, 5
^^^^
Explore code sample The splat node can be absent, in that case all target expressions are in the left field.
a, b, c = 1, 2, 3, 4, 5
^^^^^^^
: () -> Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode]
24294 24295 24296 |
# File 'lib/prism/node.rb', line 24294 def lefts @lefts end |
#lparen ⇒ String?
:call-seq:
lparen -> String | nil
Slice the location of lparen_loc from the source.
: () -> String?
24472 24473 24474 |
# File 'lib/prism/node.rb', line 24472 def lparen lparen_loc&.slice end |
#lparen_loc ⇒ Location?
:category: Locations :call-seq:
lparen_loc -> Location | nil
The Location of the opening parenthesis.
(a, b, c) = 1, 2, 3
^
: () -> Location?
24364 24365 24366 24367 24368 24369 24370 24371 24372 24373 24374 |
# File 'lib/prism/node.rb', line 24364 def lparen_loc location = @lparen_loc case location when nil nil when Location location else @lparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#newline_flag!(lines) ⇒ void
This method returns an undefined value.
: (Array lines) -> void
340 341 342 |
# File 'lib/prism/parse_result/newlines.rb', line 340 def newline_flag!(lines) # :nodoc: value.newline_flag!(lines) end |
#operator ⇒ String
:call-seq:
operator -> String
Slice the location of operator_loc from the source.
: () -> String
24492 24493 24494 |
# File 'lib/prism/node.rb', line 24492 def operator operator_loc.slice end |
#operator_loc ⇒ Location
:category: Locations :call-seq:
operator_loc -> Location
The Location of the operator.
a, b, c = 1, 2, 3
^
: () -> Location
24432 24433 24434 24435 24436 |
# File 'lib/prism/node.rb', line 24432 def operator_loc location = @operator_loc return location if location.is_a?(Location) @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#rest ⇒ ImplicitRestNode, ...
:call-seq:
rest -> ImplicitRestNode | SplatNode | nil
Represents a splat node in the target expression.
a, b, *c = 1, 2, 3, 4
^^
Explore code sample
The variable can be empty, this results in a SplatNode with a nil expression field.
a, b, * = 1, 2, 3, 4
^
Explore code sample
If the * is omitted, this field will contain an ImplicitRestNode
a, b, = 1, 2, 3, 4
^
: () -> (ImplicitRestNode | SplatNode)?
24329 24330 24331 |
# File 'lib/prism/node.rb', line 24329 def rest @rest end |
#rights ⇒ Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode]
:call-seq:
rights -> Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode]
Represents the targets expressions after a splat node.
a, *, b, c = 1, 2, 3, 4, 5
^^^^
: () -> Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode]
24346 24347 24348 |
# File 'lib/prism/node.rb', line 24346 def rights @rights end |
#rparen ⇒ String?
:call-seq:
rparen -> String | nil
Slice the location of rparen_loc from the source.
: () -> String?
24482 24483 24484 |
# File 'lib/prism/node.rb', line 24482 def rparen rparen_loc&.slice end |
#rparen_loc ⇒ Location?
:category: Locations :call-seq:
rparen_loc -> Location | nil
The Location of the closing parenthesis.
(a, b, c) = 1, 2, 3
^
: () -> Location?
24398 24399 24400 24401 24402 24403 24404 24405 24406 24407 24408 |
# File 'lib/prism/node.rb', line 24398 def rparen_loc location = @rparen_loc case location when nil nil when Location location else @rparen_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#save_lparen_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the lparen_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry?
24381 24382 24383 |
# File 'lib/prism/node.rb', line 24381 def save_lparen_loc(repository) repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil? 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
24443 24444 24445 |
# File 'lib/prism/node.rb', line 24443 def save_operator_loc(repository) repository.enter(node_id, :operator_loc) end |
#save_rparen_loc(repository) ⇒ Relocation::Entry?
:category: Repository Save the rparen_loc location using the given saved source so that it can be retrieved later.
: (_Repository repository) -> Relocation::Entry?
24415 24416 24417 |
# File 'lib/prism/node.rb', line 24415 def save_rparen_loc(repository) repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil? end |
#type ⇒ :multi_write_node
See Node#type.
: () -> :multi_write_node
24254 24255 24256 |
# File 'lib/prism/node.rb', line 24254 def type :multi_write_node end |
#value ⇒ Prism::node
:call-seq:
value -> Node
The value to write to the targets. It can be any non-void expression.
a, b, c = 1, 2, 3
^^^^^^^
: () -> Prism::node
24460 24461 24462 |
# File 'lib/prism/node.rb', line 24460 def value @value end |