Class: Prism::SuperNode

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

Overview

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

super()
^^^^^^^

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

Explore code sample If no arguments are provided (except for a block), it would be a ForwardingSuperNode instead.

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.

: (Source source, Integer node_id, Location location, Integer flags, Location keyword_loc, Location? lparen_loc, ArgumentsNode? arguments, Location? rparen_loc, (BlockNode | BlockArgumentNode)? block) -> void

Parameters:



31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
# File 'lib/prism/node.rb', line 31292

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

Class Method Details

.type ⇒ :super_node

See Node.type.

: () -> :super_node

Returns:

  • (:super_node)


31392
31393
31394
# File 'lib/prism/node.rb', line 31392

def self.type
  :super_node
end

Instance Method Details

#===(other) ⇒ boolish

: (untyped other) -> boolish

Parameters:

  • other (Object)

Returns:

  • (boolish)


31534
31535
31536
31537
31538
31539
31540
31541
# File 'lib/prism/node.rb', line 31534

def ===(other) # :nodoc:
  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

See Node.accept.

: (_Visitor visitor) -> untyped

Parameters:

Returns:

  • (Object)


31318
31319
31320
# File 'lib/prism/node.rb', line 31318

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

#arguments ⇒ ArgumentsNode?

:call-seq:

arguments -> ArgumentsNode | nil

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

: () -> ArgumentsNode?

Returns:



31458
31459
31460
# File 'lib/prism/node.rb', line 31458

def arguments
  @arguments
end

#block ⇒ BlockNode, ...

:call-seq:

block -> BlockNode | BlockArgumentNode | nil

Returns the block attribute.

: () -> (BlockNode | BlockArgumentNode)?

Returns:



31495
31496
31497
# File 'lib/prism/node.rb', line 31495

def block
  @block
end

#child_nodes ⇒ Array[node?] Also known as: deconstruct

See Node.child_nodes.

: () -> Array

Returns:

  • (Array[node?])


31325
31326
31327
# File 'lib/prism/node.rb', line 31325

def child_nodes
  [arguments, block]
end

#compact_child_nodes ⇒ Array[node]

See Node.compact_child_nodes.

: () -> Array

Returns:

  • (Array[node])


31343
31344
31345
31346
31347
31348
# File 'lib/prism/node.rb', line 31343

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  if (arguments = self.arguments); compact << arguments; end
  if (block = self.block); compact << block; end
  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) ⇒ SuperNode

:call-seq:

copy(**fields) -> SuperNode

Creates a copy of self with the given fields, using self as the template.

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

Parameters:

  • node_id: (Integer) (defaults to: self.node_id)
  • location: (Location) (defaults to: self.location)
  • flags: (Integer) (defaults to: self.flags)
  • keyword_loc: (Location) (defaults to: self.keyword_loc)
  • lparen_loc: (Location, nil) (defaults to: self.lparen_loc)
  • arguments: (ArgumentsNode, nil) (defaults to: self.arguments)
  • rparen_loc: (Location, nil) (defaults to: self.rparen_loc)
  • block: (BlockNode, BlockArgumentNode, nil) (defaults to: self.block)

Returns:



31356
31357
31358
# File 'lib/prism/node.rb', line 31356

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) ⇒ Hash[Symbol, untyped]

: (Array? keys) -> Hash[Symbol, untyped]

Parameters:

  • keys (Array[Symbol], nil)

Returns:

  • (Hash[Symbol, untyped])


31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
# File 'lib/prism/node.rb', line 31363

def deconstruct_keys(keys) # :nodoc:
  (keys || %i[node_id location keyword_loc lparen_loc arguments rparen_loc block keyword lparen rparen]).each_with_object(
    {} #: Hash[Symbol, untyped]
  ) do |key, deconstructed|
    case key
    when :node_id                 then deconstructed[:node_id] = self.node_id
    when :location                then deconstructed[:location] = self.location
    when :keyword_loc             then deconstructed[:keyword_loc] = self.keyword_loc
    when :lparen_loc              then deconstructed[:lparen_loc] = self.lparen_loc
    when :arguments               then deconstructed[:arguments] = self.arguments
    when :rparen_loc              then deconstructed[:rparen_loc] = self.rparen_loc
    when :block                   then deconstructed[:block] = self.block
    when :keyword                 then deconstructed[:keyword] = self.keyword
    when :lparen                  then deconstructed[:lparen] = self.lparen
    when :rparen                  then deconstructed[:rparen] = self.rparen
    end
  end
end

#each_child_node ⇒ Enumerator[node, void] #each_child_node ⇒ void

See Node.each_child_node.

: () -> Enumerator[node, void] : () { (node) -> void } -> void

Overloads:

  • #each_child_node ⇒ Enumerator[node, void]

    Returns:

    • (Enumerator[node, void])
  • #each_child_node ⇒ void

    This method returns an undefined value.

Yields:

Yield Parameters:

  • arg0 (node)

Yield Returns:

  • (void)


31333
31334
31335
31336
31337
31338
# File 'lib/prism/node.rb', line 31333

def each_child_node(&blk)
  return to_enum(:each_child_node) unless block_given?

  if (arguments = self.arguments); yield arguments; end
  if (block = self.block); yield block; end
end

#inspect ⇒ String

: () -> String

Returns:

  • (String)


31397
31398
31399
# File 'lib/prism/node.rb', line 31397

def inspect # :nodoc:
  InspectVisitor.compose(self)
end

#keyword ⇒ String

:call-seq:

keyword -> String

Slice the location of keyword_loc from the source.

: () -> String

Returns:

  • (String)


31507
31508
31509
# File 'lib/prism/node.rb', line 31507

def keyword
  keyword_loc.slice
end

#keyword_loc ⇒ Location

:category: Locations :call-seq:

keyword_loc -> Location

Returns the Location represented by keyword_loc.

: () -> Location

Returns:



31410
31411
31412
31413
31414
# File 'lib/prism/node.rb', line 31410

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

#lparen ⇒ String?

:call-seq:

lparen -> String | nil

Slice the location of lparen_loc from the source.

: () -> String?

Returns:

  • (String, nil)


31517
31518
31519
# File 'lib/prism/node.rb', line 31517

def lparen
  lparen_loc&.slice
end

#lparen_loc ⇒ Location?

:category: Locations :call-seq:

lparen_loc -> Location | nil

Returns the Location represented by lparen_loc.

: () -> Location?

Returns:



31432
31433
31434
31435
31436
31437
31438
31439
31440
31441
31442
# File 'lib/prism/node.rb', line 31432

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 ⇒ String?

:call-seq:

rparen -> String | nil

Slice the location of rparen_loc from the source.

: () -> String?

Returns:

  • (String, nil)


31527
31528
31529
# File 'lib/prism/node.rb', line 31527

def rparen
  rparen_loc&.slice
end

#rparen_loc ⇒ Location?

:category: Locations :call-seq:

rparen_loc -> Location | nil

Returns the Location represented by rparen_loc.

: () -> Location?

Returns:



31469
31470
31471
31472
31473
31474
31475
31476
31477
31478
31479
# File 'lib/prism/node.rb', line 31469

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) ⇒ Relocation::Entry

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

: (_Repository repository) -> Relocation::Entry

Parameters:

Returns:



31421
31422
31423
# File 'lib/prism/node.rb', line 31421

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

#save_lparen_loc(repository) ⇒ Relocation::Entry?

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

: (_Repository repository) -> Relocation::Entry?

Parameters:

Returns:



31449
31450
31451
# File 'lib/prism/node.rb', line 31449

def save_lparen_loc(repository)
  repository.enter(node_id, :lparen_loc) unless @lparen_loc.nil?
end

#save_rparen_loc(repository) ⇒ Relocation::Entry?

:category: Repository Save the rparen_loc location using the given saved source so that it can be retrieved later.

: (_Repository repository) -> Relocation::Entry?

Parameters:

Returns:



31486
31487
31488
# File 'lib/prism/node.rb', line 31486

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

#type ⇒ :super_node

See Node#type.

: () -> :super_node

Returns:

  • (:super_node)


31385
31386
31387
# File 'lib/prism/node.rb', line 31385

def type
  :super_node
end