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.



16041
16042
16043
16044
16045
16046
16047
16048
# File 'lib/prism/node.rb', line 16041

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?



16099
16100
16101
# File 'lib/prism/node.rb', line 16099

def arguments
  @arguments
end

Class Method Details

.typeObject

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



16117
16118
16119
# File 'lib/prism/node.rb', line 16117

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.



16123
16124
16125
16126
16127
# File 'lib/prism/node.rb', line 16123

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



16051
16052
16053
# File 'lib/prism/node.rb', line 16051

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

#child_nodesObject Also known as: deconstruct

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



16056
16057
16058
# File 'lib/prism/node.rb', line 16056

def child_nodes
  [arguments]
end

#comment_targetsObject

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



16068
16069
16070
# File 'lib/prism/node.rb', line 16068

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



16061
16062
16063
16064
16065
# File 'lib/prism/node.rb', line 16061

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



16073
16074
16075
# File 'lib/prism/node.rb', line 16073

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? }



16081
16082
16083
# File 'lib/prism/node.rb', line 16081

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

#inspectObject

def inspect -> String



16107
16108
16109
# File 'lib/prism/node.rb', line 16107

def inspect
  InspectVisitor.compose(self)
end

#keywordObject

def keyword: () -> String



16102
16103
16104
# File 'lib/prism/node.rb', line 16102

def keyword
  keyword_loc.slice
end

#keyword_locObject

attr_reader keyword_loc: Location



16086
16087
16088
16089
16090
# File 'lib/prism/node.rb', line 16086

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

#save_keyword_loc(repository) ⇒ Object

Save the keyword_loc location using the given saved source so that it can be retrieved later.



16094
16095
16096
# File 'lib/prism/node.rb', line 16094

def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end

#typeObject

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



16112
16113
16114
# File 'lib/prism/node.rb', line 16112

def type
  :return_node
end