Class: Prism::SuperNode

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

Overview

Represents the use of the ‘super` keyword with parentheses or arguments.

super()
^^^^^^^

super foo, bar
^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc, block) ⇒ SuperNode

Initialize a new SuperNode node.



17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
# File 'lib/prism/node.rb', line 17218

def initialize(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc, block)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @lparen_loc = lparen_loc
  @arguments = arguments
  @rparen_loc = rparen_loc
  @block = block
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



17299
17300
17301
# File 'lib/prism/node.rb', line 17299

def arguments
  @arguments
end

#blockObject (readonly)

attr_reader block: BlockNode | BlockArgumentNode | nil



17321
17322
17323
# File 'lib/prism/node.rb', line 17321

def block
  @block
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



17349
17350
17351
# File 'lib/prism/node.rb', line 17349

def self.type
  :super_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.



17355
17356
17357
17358
17359
17360
17361
17362
# File 'lib/prism/node.rb', line 17355

def ===(other)
  other.is_a?(SuperNode) &&
    (keyword_loc.nil? == other.keyword_loc.nil?) &&
    (lparen_loc.nil? == other.lparen_loc.nil?) &&
    (arguments === other.arguments) &&
    (rparen_loc.nil? == other.rparen_loc.nil?) &&
    (block === other.block)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



17231
17232
17233
# File 'lib/prism/node.rb', line 17231

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



17236
17237
17238
# File 'lib/prism/node.rb', line 17236

def child_nodes
  [arguments, block]
end

#comment_targetsObject

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



17249
17250
17251
# File 'lib/prism/node.rb', line 17249

def comment_targets
  [keyword_loc, *lparen_loc, *arguments, *rparen_loc, *block] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



17241
17242
17243
17244
17245
17246
# File 'lib/prism/node.rb', line 17241

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << arguments if arguments
  compact << block if block
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc, block: self.block) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?lparen_loc: Location?, ?arguments: ArgumentsNode?, ?rparen_loc: Location?, ?block: BlockNode | BlockArgumentNode | nil) -> SuperNode



17254
17255
17256
# File 'lib/prism/node.rb', line 17254

def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, lparen_loc: self.lparen_loc, arguments: self.arguments, rparen_loc: self.rparen_loc, block: self.block)
  SuperNode.new(source, node_id, location, flags, keyword_loc, lparen_loc, arguments, rparen_loc, block)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, lparen_loc: Location?, arguments: ArgumentsNode?, rparen_loc: Location?, block: BlockNode | BlockArgumentNode | nil }



17262
17263
17264
# File 'lib/prism/node.rb', line 17262

def deconstruct_keys(keys)
  { node_id: node_id, location: location, keyword_loc: keyword_loc, lparen_loc: lparen_loc, arguments: arguments, rparen_loc: rparen_loc, block: block }
end

#inspectObject

def inspect -> String



17339
17340
17341
# File 'lib/prism/node.rb', line 17339

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



17324
17325
17326
# File 'lib/prism/node.rb', line 17324

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



17267
17268
17269
17270
17271
# File 'lib/prism/node.rb', line 17267

def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#lparenObject

def lparen: () -> String?



17329
17330
17331
# File 'lib/prism/node.rb', line 17329

def lparen
  lparen_loc&.slice
end

#lparen_locObject

attr_reader lparen_loc: Location?



17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
# File 'lib/prism/node.rb', line 17280

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

#rparenObject

def rparen: () -> String?



17334
17335
17336
# File 'lib/prism/node.rb', line 17334

def rparen
  rparen_loc&.slice
end

#rparen_locObject

attr_reader rparen_loc: Location?



17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
# File 'lib/prism/node.rb', line 17302

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_keyword_loc(repository) ⇒ Object

Save the keyword_loc location using the given saved source so that it can be retrieved later.



17275
17276
17277
# File 'lib/prism/node.rb', line 17275

def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end

#save_lparen_loc(repository) ⇒ Object

Save the lparen_loc location using the given saved source so that it can be retrieved later.



17294
17295
17296
# File 'lib/prism/node.rb', line 17294

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.



17316
17317
17318
# File 'lib/prism/node.rb', line 17316

def save_rparen_loc(repository)
  repository.enter(node_id, :rparen_loc) unless @rparen_loc.nil?
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



17344
17345
17346
# File 'lib/prism/node.rb', line 17344

def type
  :super_node
end