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
^^^^^^^^^^^^^^

If no arguments are provided (except for a block), it would be a ‘ForwardingSuperNode` instead.

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.



17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
# File 'lib/prism/node.rb', line 17257

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)

Can be only ‘nil` when there are empty parentheses, like `super()`.



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

def arguments
  @arguments
end

#blockObject (readonly)

attr_reader block: BlockNode | BlockArgumentNode | nil



17360
17361
17362
# File 'lib/prism/node.rb', line 17360

def block
  @block
end

Class Method Details

.typeObject

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



17388
17389
17390
# File 'lib/prism/node.rb', line 17388

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.



17394
17395
17396
17397
17398
17399
17400
17401
# File 'lib/prism/node.rb', line 17394

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



17270
17271
17272
# File 'lib/prism/node.rb', line 17270

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



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

def child_nodes
  [arguments, block]
end

#comment_targetsObject

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



17288
17289
17290
# File 'lib/prism/node.rb', line 17288

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



17280
17281
17282
17283
17284
17285
# File 'lib/prism/node.rb', line 17280

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



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

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 }



17301
17302
17303
# File 'lib/prism/node.rb', line 17301

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



17378
17379
17380
# File 'lib/prism/node.rb', line 17378

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



17363
17364
17365
# File 'lib/prism/node.rb', line 17363

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



17306
17307
17308
17309
17310
# File 'lib/prism/node.rb', line 17306

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?



17368
17369
17370
# File 'lib/prism/node.rb', line 17368

def lparen
  lparen_loc&.slice
end

#lparen_locObject

attr_reader lparen_loc: Location?



17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
# File 'lib/prism/node.rb', line 17319

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?



17373
17374
17375
# File 'lib/prism/node.rb', line 17373

def rparen
  rparen_loc&.slice
end

#rparen_locObject

attr_reader rparen_loc: Location?



17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
# File 'lib/prism/node.rb', line 17341

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.



17314
17315
17316
# File 'lib/prism/node.rb', line 17314

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.



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

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.



17355
17356
17357
# File 'lib/prism/node.rb', line 17355

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`.



17383
17384
17385
# File 'lib/prism/node.rb', line 17383

def type
  :super_node
end