Class: SyntaxTree::Return

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

Overview

Return represents using the return keyword with arguments.

return value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Return.



10525
10526
10527
10528
10529
# File 'lib/syntax_tree.rb', line 10525

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

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments being passed to the keyword



10517
10518
10519
# File 'lib/syntax_tree.rb', line 10517

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10523
10524
10525
# File 'lib/syntax_tree.rb', line 10523

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10520
10521
10522
# File 'lib/syntax_tree.rb', line 10520

def location
  @location
end

Instance Method Details

#child_nodesObject



10531
10532
10533
# File 'lib/syntax_tree.rb', line 10531

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



10535
10536
10537
# File 'lib/syntax_tree.rb', line 10535

def format(q)
  FlowControlFormatter.new("return", self).format(q)
end

#pretty_print(q) ⇒ Object



10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
# File 'lib/syntax_tree.rb', line 10539

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

    q.breakable
    q.pp(arguments)

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

#to_json(*opts) ⇒ Object



10550
10551
10552
10553
10554
# File 'lib/syntax_tree.rb', line 10550

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