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.



10601
10602
10603
10604
10605
# File 'lib/syntax_tree.rb', line 10601

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



10593
10594
10595
# File 'lib/syntax_tree.rb', line 10593

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10599
10600
10601
# File 'lib/syntax_tree.rb', line 10599

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10596
10597
10598
# File 'lib/syntax_tree.rb', line 10596

def location
  @location
end

Instance Method Details

#child_nodesObject



10607
10608
10609
# File 'lib/syntax_tree.rb', line 10607

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



10611
10612
10613
# File 'lib/syntax_tree.rb', line 10611

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

#pretty_print(q) ⇒ Object



10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
# File 'lib/syntax_tree.rb', line 10615

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



10626
10627
10628
10629
10630
# File 'lib/syntax_tree.rb', line 10626

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