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.



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

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

Instance Attribute Details

#argumentsObject (readonly)

nil | Args

the arguments being passed to the keyword



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

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



9761
9762
9763
# File 'lib/syntax_tree/node.rb', line 9761

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

#accept(visitor) ⇒ Object



9732
9733
9734
# File 'lib/syntax_tree/node.rb', line 9732

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

#child_nodesObject Also known as: deconstruct



9736
9737
9738
# File 'lib/syntax_tree/node.rb', line 9736

def child_nodes
  [arguments]
end

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



9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
# File 'lib/syntax_tree/node.rb', line 9740

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



9753
9754
9755
# File 'lib/syntax_tree/node.rb', line 9753

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

#format(q) ⇒ Object



9757
9758
9759
# File 'lib/syntax_tree/node.rb', line 9757

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