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.



8226
8227
8228
8229
8230
# File 'lib/syntax_tree/node.rb', line 8226

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



8221
8222
8223
# File 'lib/syntax_tree/node.rb', line 8221

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8224
8225
8226
# File 'lib/syntax_tree/node.rb', line 8224

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



8232
8233
8234
# File 'lib/syntax_tree/node.rb', line 8232

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

#child_nodesObject Also known as: deconstruct



8236
8237
8238
# File 'lib/syntax_tree/node.rb', line 8236

def child_nodes
  [arguments]
end

#deconstruct_keys(keys) ⇒ Object



8242
8243
8244
# File 'lib/syntax_tree/node.rb', line 8242

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

#format(q) ⇒ Object



8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
# File 'lib/syntax_tree/node.rb', line 8246

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