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.



11558
11559
11560
11561
11562
# File 'lib/syntax_tree.rb', line 11558

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

Instance Attribute Details

#argumentsObject (readonly)

ArgParen | Args

the arguments to the keyword



11550
11551
11552
# File 'lib/syntax_tree.rb', line 11550

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11556
11557
11558
# File 'lib/syntax_tree.rb', line 11556

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11553
11554
11555
# File 'lib/syntax_tree.rb', line 11553

def location
  @location
end

Instance Method Details

#child_nodesObject



11564
11565
11566
# File 'lib/syntax_tree.rb', line 11564

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
# File 'lib/syntax_tree.rb', line 11568

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



11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
# File 'lib/syntax_tree.rb', line 11581

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



11592
11593
11594
11595
11596
# File 'lib/syntax_tree.rb', line 11592

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