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.



8724
8725
8726
8727
8728
# File 'lib/syntax_tree/node.rb', line 8724

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



8719
8720
8721
# File 'lib/syntax_tree/node.rb', line 8719

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8722
8723
8724
# File 'lib/syntax_tree/node.rb', line 8722

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



8730
8731
8732
# File 'lib/syntax_tree/node.rb', line 8730

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

#child_nodesObject Also known as: deconstruct



8734
8735
8736
# File 'lib/syntax_tree/node.rb', line 8734

def child_nodes
  [arguments]
end

#deconstruct_keys(_keys) ⇒ Object



8740
8741
8742
# File 'lib/syntax_tree/node.rb', line 8740

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

#format(q) ⇒ Object



8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
# File 'lib/syntax_tree/node.rb', line 8744

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