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

#pretty_print, #to_json

Constructor Details

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

Returns a new instance of Super.



7683
7684
7685
7686
7687
# File 'lib/syntax_tree/node.rb', line 7683

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



7678
7679
7680
# File 'lib/syntax_tree/node.rb', line 7678

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



7681
7682
7683
# File 'lib/syntax_tree/node.rb', line 7681

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



7689
7690
7691
# File 'lib/syntax_tree/node.rb', line 7689

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

#child_nodesObject Also known as: deconstruct



7693
7694
7695
# File 'lib/syntax_tree/node.rb', line 7693

def child_nodes
  [arguments]
end

#deconstruct_keys(keys) ⇒ Object



7699
7700
7701
# File 'lib/syntax_tree/node.rb', line 7699

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

#format(q) ⇒ Object



7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
# File 'lib/syntax_tree/node.rb', line 7703

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