Class: SyntaxTree::Return

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

Overview

Return represents using the return keyword with arguments.

return value

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Return.



8822
8823
8824
8825
8826
# File 'lib/syntax_tree/node.rb', line 8822

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



8817
8818
8819
# File 'lib/syntax_tree/node.rb', line 8817

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8820
8821
8822
# File 'lib/syntax_tree/node.rb', line 8820

def comments
  @comments
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



8828
8829
8830
# File 'lib/syntax_tree/node.rb', line 8828

def child_nodes
  [arguments]
end

#deconstruct_keys(keys) ⇒ Object



8834
8835
8836
# File 'lib/syntax_tree/node.rb', line 8834

def deconstruct_keys(keys)
  { arguments: arguments, location: location, comments: comments }
end

#format(q) ⇒ Object



8838
8839
8840
# File 'lib/syntax_tree/node.rb', line 8838

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

#pretty_print(q) ⇒ Object



8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
# File 'lib/syntax_tree/node.rb', line 8842

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



8853
8854
8855
8856
8857
# File 'lib/syntax_tree/node.rb', line 8853

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