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.



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

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



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

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [arguments]
end

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



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

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



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

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

#format(q) ⇒ Object



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

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