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.



15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
# File 'lib/prism/node.rb', line 15419

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?



15488
15489
15490
# File 'lib/prism/node.rb', line 15488

def arguments
  @arguments
end

#blockObject (readonly)

attr_reader block: Prism::node?



15504
15505
15506
# File 'lib/prism/node.rb', line 15504

def block
  @block
end

Class Method Details

.typeObject

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



15532
15533
15534
# File 'lib/prism/node.rb', line 15532

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.



15538
15539
15540
15541
15542
15543
15544
15545
# File 'lib/prism/node.rb', line 15538

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



15432
15433
15434
# File 'lib/prism/node.rb', line 15432

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

#child_nodesObject Also known as: deconstruct

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



15437
15438
15439
# File 'lib/prism/node.rb', line 15437

def child_nodes
  [arguments, block]
end

#comment_targetsObject

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



15450
15451
15452
# File 'lib/prism/node.rb', line 15450

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



15442
15443
15444
15445
15446
15447
# File 'lib/prism/node.rb', line 15442

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: Prism::node?) -> SuperNode



15455
15456
15457
# File 'lib/prism/node.rb', line 15455

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: Prism::node? }



15463
15464
15465
# File 'lib/prism/node.rb', line 15463

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



15522
15523
15524
# File 'lib/prism/node.rb', line 15522

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



15507
15508
15509
# File 'lib/prism/node.rb', line 15507

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



15468
15469
15470
15471
15472
# File 'lib/prism/node.rb', line 15468

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?



15512
15513
15514
# File 'lib/prism/node.rb', line 15512

def lparen
  lparen_loc&.slice
end

#lparen_locObject

attr_reader lparen_loc: Location?



15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
# File 'lib/prism/node.rb', line 15475

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?



15517
15518
15519
# File 'lib/prism/node.rb', line 15517

def rparen
  rparen_loc&.slice
end

#rparen_locObject

attr_reader rparen_loc: Location?



15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
# File 'lib/prism/node.rb', line 15491

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

#typeObject

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



15527
15528
15529
# File 'lib/prism/node.rb', line 15527

def type
  :super_node
end