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



9571
9572
9573
9574
9575
# File 'lib/syntax_tree/node.rb', line 9571

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

Instance Attribute Details

#argumentsObject (readonly)

nil | Args

the arguments being passed to the keyword



9566
9567
9568
# File 'lib/syntax_tree/node.rb', line 9566

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9569
9570
9571
# File 'lib/syntax_tree/node.rb', line 9569

def comments
  @comments
end

Instance Method Details

#===(other) ⇒ Object



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

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

#accept(visitor) ⇒ Object



9577
9578
9579
# File 'lib/syntax_tree/node.rb', line 9577

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

#child_nodesObject Also known as: deconstruct



9581
9582
9583
# File 'lib/syntax_tree/node.rb', line 9581

def child_nodes
  [arguments]
end

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



9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
# File 'lib/syntax_tree/node.rb', line 9585

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



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

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

#format(q) ⇒ Object



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

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