Class: SyntaxTree::ReturnNode

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

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(arguments:, location:) ⇒ ReturnNode

Returns a new instance of ReturnNode.



9693
9694
9695
9696
9697
# File 'lib/syntax_tree/node.rb', line 9693

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

Instance Attribute Details

#argumentsObject (readonly)

nil | Args

the arguments being passed to the keyword



9688
9689
9690
# File 'lib/syntax_tree/node.rb', line 9688

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9691
9692
9693
# File 'lib/syntax_tree/node.rb', line 9691

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



9728
9729
9730
# File 'lib/syntax_tree/node.rb', line 9728

def ===(other)
  other.is_a?(ReturnNode) && arguments === other.arguments
end

#accept(visitor) ⇒ Object



9699
9700
9701
# File 'lib/syntax_tree/node.rb', line 9699

def accept(visitor)
  visitor.visit_return(self)
end

#child_nodesObject Also known as: deconstruct



9703
9704
9705
# File 'lib/syntax_tree/node.rb', line 9703

def child_nodes
  [arguments]
end

#copy(arguments: nil, location: nil) ⇒ Object



9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
# File 'lib/syntax_tree/node.rb', line 9707

def copy(arguments: nil, location: nil)
  node =
    ReturnNode.new(
      arguments: arguments || self.arguments,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



9720
9721
9722
# File 'lib/syntax_tree/node.rb', line 9720

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

#format(q) ⇒ Object



9724
9725
9726
# File 'lib/syntax_tree/node.rb', line 9724

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