Class: SyntaxTree::Super

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Super represents using the super keyword with arguments. It can optionally use parentheses.

super(value)

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(arguments:, location:) ⇒ Super

Returns a new instance of Super.



10436
10437
10438
10439
10440
# File 'lib/syntax_tree/node.rb', line 10436

def initialize(arguments:, location:)
  @arguments = arguments
  @location = location
  @comments = []
end

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



10431
10432
10433
# File 'lib/syntax_tree/node.rb', line 10431

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10434
10435
10436
# File 'lib/syntax_tree/node.rb', line 10434

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



10480
10481
10482
# File 'lib/syntax_tree/node.rb', line 10480

def ===(other)
  other.is_a?(Super) && arguments === other.arguments
end

#accept(visitor) ⇒ Object



10442
10443
10444
# File 'lib/syntax_tree/node.rb', line 10442

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

#child_nodesObject Also known as: deconstruct



10446
10447
10448
# File 'lib/syntax_tree/node.rb', line 10446

def child_nodes
  [arguments]
end

#copy(arguments: nil, location: nil) ⇒ Object



10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
# File 'lib/syntax_tree/node.rb', line 10450

def copy(arguments: nil, location: nil)
  node =
    Super.new(
      arguments: arguments || self.arguments,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



10463
10464
10465
# File 'lib/syntax_tree/node.rb', line 10463

def deconstruct_keys(_keys)
  { arguments: arguments, location: location, comments: comments }
end

#format(q) ⇒ Object



10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
# File 'lib/syntax_tree/node.rb', line 10467

def format(q)
  q.group do
    q.text("super")

    if arguments.is_a?(ArgParen)
      q.format(arguments)
    else
      q.text(" ")
      q.nest("super ".length) { q.format(arguments) }
    end
  end
end