Class: Prism::ReturnNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
ext/prism/api_node.c

Overview

Represents the use of the ‘return` keyword.

return 1
^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, keyword_loc, arguments) ⇒ ReturnNode

Initialize a new ReturnNode node.



14493
14494
14495
14496
14497
14498
14499
14500
# File 'lib/prism/node.rb', line 14493

def initialize(source, node_id, location, flags, keyword_loc, arguments)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @arguments = arguments
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



14545
14546
14547
# File 'lib/prism/node.rb', line 14545

def arguments
  @arguments
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



14563
14564
14565
# File 'lib/prism/node.rb', line 14563

def self.type
  :return_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



14569
14570
14571
14572
14573
# File 'lib/prism/node.rb', line 14569

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



14503
14504
14505
# File 'lib/prism/node.rb', line 14503

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



14508
14509
14510
# File 'lib/prism/node.rb', line 14508

def child_nodes
  [arguments]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



14520
14521
14522
# File 'lib/prism/node.rb', line 14520

def comment_targets
  [keyword_loc, *arguments] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14513
14514
14515
14516
14517
# File 'lib/prism/node.rb', line 14513

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact << arguments if arguments
  compact
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, arguments: self.arguments) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?arguments: ArgumentsNode?) -> ReturnNode



14525
14526
14527
# File 'lib/prism/node.rb', line 14525

def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, arguments: self.arguments)
  ReturnNode.new(source, node_id, location, flags, keyword_loc, arguments)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, arguments: ArgumentsNode? }



14533
14534
14535
# File 'lib/prism/node.rb', line 14533

def deconstruct_keys(keys)
  { node_id: node_id, location: location, keyword_loc: keyword_loc, arguments: arguments }
end

#inspectObject

def inspect -> String



14553
14554
14555
# File 'lib/prism/node.rb', line 14553

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



14548
14549
14550
# File 'lib/prism/node.rb', line 14548

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



14538
14539
14540
14541
14542
# File 'lib/prism/node.rb', line 14538

def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



14558
14559
14560
# File 'lib/prism/node.rb', line 14558

def type
  :return_node
end