Class: YARP::MultiTargetNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents a multi-target expression.

a, b, c = 1, 2, 3
^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(targets, lparen_loc, rparen_loc, location) ⇒ MultiTargetNode

def initialize: (targets: Array, lparen_loc: Location?, rparen_loc: Location?, location: Location) -> void



7196
7197
7198
7199
7200
7201
# File 'lib/yarp/node.rb', line 7196

def initialize(targets, lparen_loc, rparen_loc, location)
  @targets = targets
  @lparen_loc = lparen_loc
  @rparen_loc = rparen_loc
  @location = location
end

Instance Attribute Details

#lparen_locObject (readonly)

attr_reader lparen_loc: Location?



7190
7191
7192
# File 'lib/yarp/node.rb', line 7190

def lparen_loc
  @lparen_loc
end

#rparen_locObject (readonly)

attr_reader rparen_loc: Location?



7193
7194
7195
# File 'lib/yarp/node.rb', line 7193

def rparen_loc
  @rparen_loc
end

#targetsObject (readonly)

attr_reader targets: Array



7187
7188
7189
# File 'lib/yarp/node.rb', line 7187

def targets
  @targets
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



7204
7205
7206
# File 'lib/yarp/node.rb', line 7204

def accept(visitor)
  visitor.visit_multi_target_node(self)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



7209
7210
7211
# File 'lib/yarp/node.rb', line 7209

def child_nodes
  [*targets]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



7214
7215
7216
# File 'lib/yarp/node.rb', line 7214

def comment_targets
  [*targets, *lparen_loc, *rparen_loc]
end

#copy(**params) ⇒ Object

def copy: (**params) -> MultiTargetNode



7219
7220
7221
7222
7223
7224
7225
7226
# File 'lib/yarp/node.rb', line 7219

def copy(**params)
  MultiTargetNode.new(
    params.fetch(:targets) { targets },
    params.fetch(:lparen_loc) { lparen_loc },
    params.fetch(:rparen_loc) { rparen_loc },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



7232
7233
7234
# File 'lib/yarp/node.rb', line 7232

def deconstruct_keys(keys)
  { targets: targets, lparen_loc: lparen_loc, rparen_loc: rparen_loc, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



7246
7247
7248
7249
7250
7251
7252
# File 'lib/yarp/node.rb', line 7246

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "├── targets: #{inspector.list("#{inspector.prefix}", targets)}"
  inspector << "├── lparen_loc: #{inspector.location(lparen_loc)}\n"
  inspector << "└── rparen_loc: #{inspector.location(rparen_loc)}\n"
  inspector.to_str
end

#lparenObject

def lparen: () -> String?



7237
7238
7239
# File 'lib/yarp/node.rb', line 7237

def lparen
  lparen_loc&.slice
end

#rparenObject

def rparen: () -> String?



7242
7243
7244
# File 'lib/yarp/node.rb', line 7242

def rparen
  rparen_loc&.slice
end