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.



10867
10868
10869
10870
10871
# File 'lib/syntax_tree.rb', line 10867

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



10859
10860
10861
# File 'lib/syntax_tree.rb', line 10859

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10865
10866
10867
# File 'lib/syntax_tree.rb', line 10865

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10862
10863
10864
# File 'lib/syntax_tree.rb', line 10862

def location
  @location
end

Instance Method Details

#child_nodesObject



10873
10874
10875
# File 'lib/syntax_tree.rb', line 10873

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
# File 'lib/syntax_tree.rb', line 10877

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



10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
# File 'lib/syntax_tree.rb', line 10890

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



10901
10902
10903
10904
10905
# File 'lib/syntax_tree.rb', line 10901

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