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.



10404
10405
10406
10407
10408
# File 'lib/syntax_tree/node.rb', line 10404

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



10399
10400
10401
# File 'lib/syntax_tree/node.rb', line 10399

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10402
10403
10404
# File 'lib/syntax_tree/node.rb', line 10402

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



10410
10411
10412
# File 'lib/syntax_tree/node.rb', line 10410

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

#child_nodesObject Also known as: deconstruct



10414
10415
10416
# File 'lib/syntax_tree/node.rb', line 10414

def child_nodes
  [arguments]
end

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



10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
# File 'lib/syntax_tree/node.rb', line 10418

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



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

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

#format(q) ⇒ Object



10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
# File 'lib/syntax_tree/node.rb', line 10435

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