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

Constructor Details

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

Returns a new instance of Super.



9480
9481
9482
9483
9484
# File 'lib/syntax_tree/node.rb', line 9480

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

Instance Attribute Details

#argumentsObject (readonly)

[ArgParen | Args] the arguments to the keyword



9475
9476
9477
# File 'lib/syntax_tree/node.rb', line 9475

def arguments
  @arguments
end

#commentsObject (readonly)

[Array[ Comment | EmbDoc ]] the comments attached to this node



9478
9479
9480
# File 'lib/syntax_tree/node.rb', line 9478

def comments
  @comments
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



9486
9487
9488
# File 'lib/syntax_tree/node.rb', line 9486

def child_nodes
  [arguments]
end

#deconstruct_keys(keys) ⇒ Object



9492
9493
9494
# File 'lib/syntax_tree/node.rb', line 9492

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

#format(q) ⇒ Object



9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
# File 'lib/syntax_tree/node.rb', line 9496

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

#pretty_print(q) ⇒ Object



9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
# File 'lib/syntax_tree/node.rb', line 9509

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("super")

    q.breakable
    q.pp(arguments)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



9520
9521
9522
9523
9524
# File 'lib/syntax_tree/node.rb', line 9520

def to_json(*opts)
  { type: :super, args: arguments, loc: location, cmts: comments }.to_json(
    *opts
  )
end