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.



15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
# File 'lib/prism/node.rb', line 15456

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?



15525
15526
15527
# File 'lib/prism/node.rb', line 15525

def arguments
  @arguments
end

#blockObject (readonly)

attr_reader block: BlockNode | BlockArgumentNode | nil



15541
15542
15543
# File 'lib/prism/node.rb', line 15541

def block
  @block
end

Class Method Details

.typeObject

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



15569
15570
15571
# File 'lib/prism/node.rb', line 15569

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.



15575
15576
15577
15578
15579
15580
15581
15582
# File 'lib/prism/node.rb', line 15575

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



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

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

#child_nodesObject Also known as: deconstruct

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



15474
15475
15476
# File 'lib/prism/node.rb', line 15474

def child_nodes
  [arguments, block]
end

#comment_targetsObject

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



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

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



15479
15480
15481
15482
15483
15484
# File 'lib/prism/node.rb', line 15479

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



15492
15493
15494
# File 'lib/prism/node.rb', line 15492

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 }



15500
15501
15502
# File 'lib/prism/node.rb', line 15500

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



15559
15560
15561
# File 'lib/prism/node.rb', line 15559

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



15544
15545
15546
# File 'lib/prism/node.rb', line 15544

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



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

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?



15549
15550
15551
# File 'lib/prism/node.rb', line 15549

def lparen
  lparen_loc&.slice
end

#lparen_locObject

attr_reader lparen_loc: Location?



15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
# File 'lib/prism/node.rb', line 15512

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?



15554
15555
15556
# File 'lib/prism/node.rb', line 15554

def rparen
  rparen_loc&.slice
end

#rparen_locObject

attr_reader rparen_loc: Location?



15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
# File 'lib/prism/node.rb', line 15528

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



15564
15565
15566
# File 'lib/prism/node.rb', line 15564

def type
  :super_node
end