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, #pretty_print, #to_json

Constructor Details

#initialize(arguments:, location:) ⇒ ReturnNode



9597
9598
9599
9600
9601
# File 'lib/syntax_tree/node.rb', line 9597

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

Instance Attribute Details

#argumentsObject (readonly)

nil | Args

the arguments being passed to the keyword



9592
9593
9594
# File 'lib/syntax_tree/node.rb', line 9592

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9595
9596
9597
# File 'lib/syntax_tree/node.rb', line 9595

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



9632
9633
9634
# File 'lib/syntax_tree/node.rb', line 9632

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

#accept(visitor) ⇒ Object



9603
9604
9605
# File 'lib/syntax_tree/node.rb', line 9603

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

#child_nodesObject Also known as: deconstruct



9607
9608
9609
# File 'lib/syntax_tree/node.rb', line 9607

def child_nodes
  [arguments]
end

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



9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
# File 'lib/syntax_tree/node.rb', line 9611

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



9624
9625
9626
# File 'lib/syntax_tree/node.rb', line 9624

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

#format(q) ⇒ Object



9628
9629
9630
# File 'lib/syntax_tree/node.rb', line 9628

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