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.



18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
# File 'lib/prism/node.rb', line 18295

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



18384
18385
18386
# File 'lib/prism/node.rb', line 18384

def arguments
  @arguments
end

#blockObject (readonly)

attr_reader block: BlockNode | BlockArgumentNode | nil



18406
18407
18408
# File 'lib/prism/node.rb', line 18406

def block
  @block
end

Class Method Details

.typeObject

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



18434
18435
18436
# File 'lib/prism/node.rb', line 18434

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.



18440
18441
18442
18443
18444
18445
18446
18447
# File 'lib/prism/node.rb', line 18440

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



18308
18309
18310
# File 'lib/prism/node.rb', line 18308

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



18313
18314
18315
# File 'lib/prism/node.rb', line 18313

def child_nodes
  [arguments, block]
end

#comment_targetsObject

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



18334
18335
18336
# File 'lib/prism/node.rb', line 18334

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



18326
18327
18328
18329
18330
18331
# File 'lib/prism/node.rb', line 18326

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



18339
18340
18341
# File 'lib/prism/node.rb', line 18339

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 }



18347
18348
18349
# File 'lib/prism/node.rb', line 18347

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

#each_child_node {|arguments| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



18318
18319
18320
18321
18322
18323
# File 'lib/prism/node.rb', line 18318

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield arguments if arguments
  yield block if block
end

#inspectObject

def inspect -> String



18424
18425
18426
# File 'lib/prism/node.rb', line 18424

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



18409
18410
18411
# File 'lib/prism/node.rb', line 18409

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



18352
18353
18354
18355
18356
# File 'lib/prism/node.rb', line 18352

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?



18414
18415
18416
# File 'lib/prism/node.rb', line 18414

def lparen
  lparen_loc&.slice
end

#lparen_locObject

attr_reader lparen_loc: Location?



18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
# File 'lib/prism/node.rb', line 18365

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?



18419
18420
18421
# File 'lib/prism/node.rb', line 18419

def rparen
  rparen_loc&.slice
end

#rparen_locObject

attr_reader rparen_loc: Location?



18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
# File 'lib/prism/node.rb', line 18387

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.



18360
18361
18362
# File 'lib/prism/node.rb', line 18360

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.



18379
18380
18381
# File 'lib/prism/node.rb', line 18379

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.



18401
18402
18403
# File 'lib/prism/node.rb', line 18401

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



18429
18430
18431
# File 'lib/prism/node.rb', line 18429

def type
  :super_node
end