Class: SyntaxTree::Super

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

Super represents using the super keyword with arguments. It can optionally use parentheses.

super(value)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Super.



11426
11427
11428
11429
11430
# File 'lib/syntax_tree.rb', line 11426

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



11418
11419
11420
# File 'lib/syntax_tree.rb', line 11418

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11424
11425
11426
# File 'lib/syntax_tree.rb', line 11424

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11421
11422
11423
# File 'lib/syntax_tree.rb', line 11421

def location
  @location
end

Instance Method Details

#child_nodesObject



11432
11433
11434
# File 'lib/syntax_tree.rb', line 11432

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
# File 'lib/syntax_tree.rb', line 11436

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

#pretty_print(q) ⇒ Object



11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
# File 'lib/syntax_tree.rb', line 11449

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("super")

    q.breakable
    q.pp(arguments)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



11460
11461
11462
11463
11464
# File 'lib/syntax_tree.rb', line 11460

def to_json(*opts)
  { type: :super, args: arguments, loc: location, cmts: comments }.to_json(
    *opts
  )
end