Class: Prism::ReturnNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ReturnNode
- 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
-
#arguments ⇒ Object
readonly
attr_reader arguments: ArgumentsNode?.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, arguments: ArgumentsNode? }.
-
#initialize(source, node_id, location, flags, keyword_loc, arguments) ⇒ ReturnNode
constructor
Initialize a new ReturnNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#keyword ⇒ Object
def keyword: () -> String.
-
#keyword_loc ⇒ Object
attr_reader keyword_loc: Location.
-
#save_keyword_loc(repository) ⇒ Object
Save the keyword_loc location using the given saved source so that it can be retrieved later.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, keyword_loc, arguments) ⇒ ReturnNode
Initialize a new ReturnNode node.
16073 16074 16075 16076 16077 16078 16079 16080 |
# File 'lib/prism/node.rb', line 16073 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
#arguments ⇒ Object (readonly)
attr_reader arguments: ArgumentsNode?
16131 16132 16133 |
# File 'lib/prism/node.rb', line 16131 def arguments @arguments end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
16149 16150 16151 |
# File 'lib/prism/node.rb', line 16149 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.
16155 16156 16157 16158 16159 |
# File 'lib/prism/node.rb', line 16155 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
16083 16084 16085 |
# File 'lib/prism/node.rb', line 16083 def accept(visitor) visitor.visit_return_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
16088 16089 16090 |
# File 'lib/prism/node.rb', line 16088 def child_nodes [arguments] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
16100 16101 16102 |
# File 'lib/prism/node.rb', line 16100 def comment_targets [keyword_loc, *arguments] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
16093 16094 16095 16096 16097 |
# File 'lib/prism/node.rb', line 16093 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
16105 16106 16107 |
# File 'lib/prism/node.rb', line 16105 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? }
16113 16114 16115 |
# File 'lib/prism/node.rb', line 16113 def deconstruct_keys(keys) { node_id: node_id, location: location, keyword_loc: keyword_loc, arguments: arguments } end |
#inspect ⇒ Object
def inspect -> String
16139 16140 16141 |
# File 'lib/prism/node.rb', line 16139 def inspect InspectVisitor.compose(self) end |
#keyword ⇒ Object
def keyword: () -> String
16134 16135 16136 |
# File 'lib/prism/node.rb', line 16134 def keyword keyword_loc.slice end |
#keyword_loc ⇒ Object
attr_reader keyword_loc: Location
16118 16119 16120 16121 16122 |
# File 'lib/prism/node.rb', line 16118 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.
16126 16127 16128 |
# File 'lib/prism/node.rb', line 16126 def save_keyword_loc(repository) repository.enter(node_id, :keyword_loc) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
16144 16145 16146 |
# File 'lib/prism/node.rb', line 16144 def type :return_node end |