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



10281
10282
10283
10284
10285
# File 'lib/syntax_tree/node.rb', line 10281

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



10276
10277
10278
# File 'lib/syntax_tree/node.rb', line 10276

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10279
10280
10281
# File 'lib/syntax_tree/node.rb', line 10279

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



10325
10326
10327
# File 'lib/syntax_tree/node.rb', line 10325

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

#accept(visitor) ⇒ Object



10287
10288
10289
# File 'lib/syntax_tree/node.rb', line 10287

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [arguments]
end

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



10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
# File 'lib/syntax_tree/node.rb', line 10295

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



10308
10309
10310
# File 'lib/syntax_tree/node.rb', line 10308

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

#format(q) ⇒ Object



10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
# File 'lib/syntax_tree/node.rb', line 10312

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