Class: Prism::MultiTargetNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::MultiTargetNode
- Defined in:
- lib/prism/node.rb,
ext/prism/api_node.c
Overview
Represents a multi-target expression.
a, (b, c) = 1, 2, 3
^^^^^^
This can be a part of ‘MultiWriteNode` as above, or the target of a `for` loop
for a, b in [[1, 2], [3, 4]]
^^^^
Instance Attribute Summary collapse
-
#lefts ⇒ Object
readonly
Represents the targets expressions before a splat node.
-
#rest ⇒ Object
readonly
Represents a splat node in the target expression.
-
#rights ⇒ Object
readonly
Represents the targets expressions after a splat node.
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.
-
#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, lefts: self.lefts, rest: self.rest, rights: self.rights, lparen_loc: self.lparen_loc, rparen_loc: self.rparen_loc) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?lefts: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], ?rest: ImplicitRestNode | SplatNode | nil, ?rights: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], ?lparen_loc: Location?, ?rparen_loc: Location?) -> MultiTargetNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, lefts: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], rest: ImplicitRestNode | SplatNode | nil, rights: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], lparen_loc: Location?, rparen_loc: Location? }.
-
#initialize(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc) ⇒ MultiTargetNode
constructor
Initialize a new MultiTargetNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#lparen ⇒ Object
def lparen: () -> String?.
-
#lparen_loc ⇒ Object
The location of the opening parenthesis.
-
#rparen ⇒ Object
def rparen: () -> String?.
-
#rparen_loc ⇒ Object
The location of the closing parenthesis.
-
#save_lparen_loc(repository) ⇒ Object
Save the lparen_loc location using the given saved source so that it can be retrieved later.
-
#save_rparen_loc(repository) ⇒ Object
Save the rparen_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, lefts, rest, rights, lparen_loc, rparen_loc) ⇒ MultiTargetNode
Initialize a new MultiTargetNode node.
13170 13171 13172 13173 13174 13175 13176 13177 13178 13179 13180 |
# File 'lib/prism/node.rb', line 13170 def initialize(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc) @source = source @node_id = node_id @location = location @flags = flags @lefts = lefts @rest = rest @rights = rights @lparen_loc = lparen_loc @rparen_loc = rparen_loc end |
Instance Attribute Details
#lefts ⇒ Object (readonly)
Represents the targets expressions before a splat node.
a, (b, c, *) = 1, 2, 3, 4, 5
^^^^
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
^^^^
13228 13229 13230 |
# File 'lib/prism/node.rb', line 13228 def lefts @lefts end |
#rest ⇒ Object (readonly)
Represents a splat node in the target expression.
a, (b, *c) = 1, 2, 3, 4
^^
The variable can be empty, this results in a ‘SplatNode` with a `nil` expression field.
a, (b, *) = 1, 2, 3, 4
^
If the ‘*` is omitted, this field will contain an `ImplicitRestNode`
a, (b,) = 1, 2, 3, 4
^
13244 13245 13246 |
# File 'lib/prism/node.rb', line 13244 def rest @rest end |
#rights ⇒ Object (readonly)
Represents the targets expressions after a splat node.
a, (*, b, c) = 1, 2, 3, 4, 5
^^^^
13250 13251 13252 |
# File 'lib/prism/node.rb', line 13250 def rights @rights end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
13317 13318 13319 |
# File 'lib/prism/node.rb', line 13317 def self.type :multi_target_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.
13323 13324 13325 13326 13327 13328 13329 13330 13331 13332 |
# File 'lib/prism/node.rb', line 13323 def ===(other) other.is_a?(MultiTargetNode) && (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?) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
13183 13184 13185 |
# File 'lib/prism/node.rb', line 13183 def accept(visitor) visitor.visit_multi_target_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
13188 13189 13190 |
# File 'lib/prism/node.rb', line 13188 def child_nodes [*lefts, rest, *rights] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
13202 13203 13204 |
# File 'lib/prism/node.rb', line 13202 def comment_targets [*lefts, *rest, *rights, *lparen_loc, *rparen_loc] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
13193 13194 13195 13196 13197 13198 13199 |
# File 'lib/prism/node.rb', line 13193 def compact_child_nodes compact = [] #: Array[Prism::node] compact.concat(lefts) compact << rest if rest compact.concat(rights) 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) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?lefts: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], ?rest: ImplicitRestNode | SplatNode | nil, ?rights: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], ?lparen_loc: Location?, ?rparen_loc: Location?) -> MultiTargetNode
13207 13208 13209 |
# File 'lib/prism/node.rb', line 13207 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) MultiTargetNode.new(source, node_id, location, flags, lefts, rest, rights, lparen_loc, rparen_loc) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, lefts: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], rest: ImplicitRestNode | SplatNode | nil, rights: Array[LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | MultiTargetNode | RequiredParameterNode | BackReferenceReadNode | NumberedReferenceReadNode], lparen_loc: Location?, rparen_loc: Location? }
13215 13216 13217 |
# File 'lib/prism/node.rb', line 13215 def deconstruct_keys(keys) { node_id: node_id, location: location, lefts: lefts, rest: rest, rights: rights, lparen_loc: lparen_loc, rparen_loc: rparen_loc } end |
#inspect ⇒ Object
def inspect -> String
13307 13308 13309 |
# File 'lib/prism/node.rb', line 13307 def inspect InspectVisitor.compose(self) end |
#lparen ⇒ Object
def lparen: () -> String?
13297 13298 13299 |
# File 'lib/prism/node.rb', line 13297 def lparen lparen_loc&.slice end |
#lparen_loc ⇒ Object
The location of the opening parenthesis.
a, (b, c) = 1, 2, 3
^
13256 13257 13258 13259 13260 13261 13262 13263 13264 13265 13266 |
# File 'lib/prism/node.rb', line 13256 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 |
#rparen ⇒ Object
def rparen: () -> String?
13302 13303 13304 |
# File 'lib/prism/node.rb', line 13302 def rparen rparen_loc&.slice end |
#rparen_loc ⇒ Object
The location of the closing parenthesis.
a, (b, c) = 1, 2, 3
^
13278 13279 13280 13281 13282 13283 13284 13285 13286 13287 13288 |
# File 'lib/prism/node.rb', line 13278 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) ⇒ Object
Save the lparen_loc location using the given saved source so that it can be retrieved later.
13270 13271 13272 |
# File 'lib/prism/node.rb', line 13270 def save_lparen_loc(repository) repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil? end |
#save_rparen_loc(repository) ⇒ Object
Save the rparen_loc location using the given saved source so that it can be retrieved later.
13292 13293 13294 |
# File 'lib/prism/node.rb', line 13292 def save_rparen_loc(repository) repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil? end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
13312 13313 13314 |
# File 'lib/prism/node.rb', line 13312 def type :multi_target_node end |