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.



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

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

Instance Attribute Details

#argumentsObject (readonly)

nil | Args

the arguments being passed to the keyword



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

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  [arguments]
end

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



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

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



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

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

#format(q) ⇒ Object



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

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