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, #pretty_print, #to_json

Constructor Details

#initialize(arguments:, location:, comments: []) ⇒ Super

Returns a new instance of Super.



8493
8494
8495
8496
8497
# File 'lib/syntax_tree/node.rb', line 8493

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



8488
8489
8490
# File 'lib/syntax_tree/node.rb', line 8488

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8491
8492
8493
# File 'lib/syntax_tree/node.rb', line 8491

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



8499
8500
8501
# File 'lib/syntax_tree/node.rb', line 8499

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

#child_nodesObject Also known as: deconstruct



8503
8504
8505
# File 'lib/syntax_tree/node.rb', line 8503

def child_nodes
  [arguments]
end

#deconstruct_keys(_keys) ⇒ Object



8509
8510
8511
# File 'lib/syntax_tree/node.rb', line 8509

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

#format(q) ⇒ Object



8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
# File 'lib/syntax_tree/node.rb', line 8513

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