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.



8409
8410
8411
8412
8413
# File 'lib/syntax_tree/node.rb', line 8409

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



8404
8405
8406
# File 'lib/syntax_tree/node.rb', line 8404

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8407
8408
8409
# File 'lib/syntax_tree/node.rb', line 8407

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



8415
8416
8417
# File 'lib/syntax_tree/node.rb', line 8415

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

#child_nodesObject Also known as: deconstruct



8419
8420
8421
# File 'lib/syntax_tree/node.rb', line 8419

def child_nodes
  [arguments]
end

#deconstruct_keys(_keys) ⇒ Object



8425
8426
8427
# File 'lib/syntax_tree/node.rb', line 8425

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

#format(q) ⇒ Object



8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
# File 'lib/syntax_tree/node.rb', line 8429

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