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:) ⇒ Super

Returns a new instance of Super.



10246
10247
10248
10249
10250
# File 'lib/syntax_tree/node.rb', line 10246

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



10241
10242
10243
# File 'lib/syntax_tree/node.rb', line 10241

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10244
10245
10246
# File 'lib/syntax_tree/node.rb', line 10244

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



10290
10291
10292
# File 'lib/syntax_tree/node.rb', line 10290

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

#accept(visitor) ⇒ Object



10252
10253
10254
# File 'lib/syntax_tree/node.rb', line 10252

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

#child_nodesObject Also known as: deconstruct



10256
10257
10258
# File 'lib/syntax_tree/node.rb', line 10256

def child_nodes
  [arguments]
end

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



10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
# File 'lib/syntax_tree/node.rb', line 10260

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



10273
10274
10275
# File 'lib/syntax_tree/node.rb', line 10273

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

#format(q) ⇒ Object



10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
# File 'lib/syntax_tree/node.rb', line 10277

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