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



10733
10734
10735
10736
10737
# File 'lib/syntax_tree.rb', line 10733

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



10725
10726
10727
# File 'lib/syntax_tree.rb', line 10725

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



10731
10732
10733
# File 'lib/syntax_tree.rb', line 10731

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



10728
10729
10730
# File 'lib/syntax_tree.rb', line 10728

def location
  @location
end

Instance Method Details

#child_nodesObject



10739
10740
10741
# File 'lib/syntax_tree.rb', line 10739

def child_nodes
  [arguments]
end

#format(q) ⇒ Object



10743
10744
10745
# File 'lib/syntax_tree.rb', line 10743

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

#pretty_print(q) ⇒ Object



10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
# File 'lib/syntax_tree.rb', line 10747

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



10758
10759
10760
10761
10762
# File 'lib/syntax_tree.rb', line 10758

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