Class: Prism::RescueNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::RescueNode
- Defined in:
- lib/prism/node.rb,
lib/prism/node_ext.rb,
ext/prism/api_node.c
Overview
Represents a rescue statement.
begin
rescue Foo, *splat, Bar => ex
foo
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
end
‘Foo, *splat, Bar` are in the `exceptions` field. `ex` is in the `reference` field.
Instance Attribute Summary collapse
-
#exceptions ⇒ Object
readonly
attr_reader exceptions: Array.
-
#reference ⇒ Object
readonly
attr_reader reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil.
-
#statements ⇒ Object
readonly
attr_reader statements: StatementsNode?.
-
#subsequent ⇒ Object
readonly
attr_reader subsequent: RescueNode?.
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.
-
#consequent ⇒ Object
Returns the subsequent rescue clause of the rescue node.
-
#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, exceptions: self.exceptions, operator_loc: self.operator_loc, reference: self.reference, statements: self.statements, subsequent: self.subsequent) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?exceptions: Array, ?operator_loc: Location?, ?reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil, ?statements: StatementsNode?, ?subsequent: RescueNode?) -> RescueNode.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, exceptions: Array, operator_loc: Location?, reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil, statements: StatementsNode?, subsequent: RescueNode? }.
-
#initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, subsequent) ⇒ RescueNode
constructor
Initialize a new RescueNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#keyword ⇒ Object
def keyword: () -> String.
-
#keyword_loc ⇒ Object
attr_reader keyword_loc: Location.
-
#operator ⇒ Object
def operator: () -> String?.
-
#operator_loc ⇒ Object
attr_reader operator_loc: Location?.
-
#type ⇒ Object
Return a symbol representation of this node type.
Constructor Details
#initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, subsequent) ⇒ RescueNode
Initialize a new RescueNode node.
14225 14226 14227 14228 14229 14230 14231 14232 14233 14234 14235 14236 |
# File 'lib/prism/node.rb', line 14225 def initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, subsequent) @source = source @node_id = node_id @location = location @flags = flags @keyword_loc = keyword_loc @exceptions = exceptions @operator_loc = operator_loc @reference = reference @statements = statements @subsequent = subsequent end |
Instance Attribute Details
#exceptions ⇒ Object (readonly)
attr_reader exceptions: Array
14284 14285 14286 |
# File 'lib/prism/node.rb', line 14284 def exceptions @exceptions end |
#reference ⇒ Object (readonly)
attr_reader reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil
14300 14301 14302 |
# File 'lib/prism/node.rb', line 14300 def reference @reference end |
#statements ⇒ Object (readonly)
attr_reader statements: StatementsNode?
14303 14304 14305 |
# File 'lib/prism/node.rb', line 14303 def statements @statements end |
#subsequent ⇒ Object (readonly)
attr_reader subsequent: RescueNode?
14306 14307 14308 |
# File 'lib/prism/node.rb', line 14306 def subsequent @subsequent end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
14329 14330 14331 |
# File 'lib/prism/node.rb', line 14329 def self.type :rescue_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.
14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 |
# File 'lib/prism/node.rb', line 14335 def ===(other) other.is_a?(RescueNode) && (keyword_loc.nil? == other.keyword_loc.nil?) && (exceptions.length == other.exceptions.length) && exceptions.zip(other.exceptions).all? { |left, right| left === right } && (operator_loc.nil? == other.operator_loc.nil?) && (reference === other.reference) && (statements === other.statements) && (subsequent === other.subsequent) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
14239 14240 14241 |
# File 'lib/prism/node.rb', line 14239 def accept(visitor) visitor.visit_rescue_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
14244 14245 14246 |
# File 'lib/prism/node.rb', line 14244 def child_nodes [*exceptions, reference, statements, subsequent] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
14259 14260 14261 |
# File 'lib/prism/node.rb', line 14259 def comment_targets [keyword_loc, *exceptions, *operator_loc, *reference, *statements, *subsequent] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
14249 14250 14251 14252 14253 14254 14255 14256 |
# File 'lib/prism/node.rb', line 14249 def compact_child_nodes compact = [] #: Array[Prism::node] compact.concat(exceptions) compact << reference if reference compact << statements if statements compact << subsequent if subsequent compact end |
#consequent ⇒ Object
Returns the subsequent rescue clause of the rescue node. This method is deprecated in favor of #subsequent.
494 495 496 497 |
# File 'lib/prism/node_ext.rb', line 494 def consequent deprecated("subsequent") subsequent end |
#copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, exceptions: self.exceptions, operator_loc: self.operator_loc, reference: self.reference, statements: self.statements, subsequent: self.subsequent) ⇒ Object
def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?exceptions: Array, ?operator_loc: Location?, ?reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil, ?statements: StatementsNode?, ?subsequent: RescueNode?) -> RescueNode
14264 14265 14266 |
# File 'lib/prism/node.rb', line 14264 def copy(node_id: self.node_id, location: self.location, flags: self.flags, keyword_loc: self.keyword_loc, exceptions: self.exceptions, operator_loc: self.operator_loc, reference: self.reference, statements: self.statements, subsequent: self.subsequent) RescueNode.new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, subsequent) end |
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, exceptions: Array, operator_loc: Location?, reference: LocalVariableTargetNode | InstanceVariableTargetNode | ClassVariableTargetNode | GlobalVariableTargetNode | ConstantTargetNode | ConstantPathTargetNode | CallTargetNode | IndexTargetNode | BackReferenceReadNode | NumberedReferenceReadNode | MissingNode | nil, statements: StatementsNode?, subsequent: RescueNode? }
14272 14273 14274 |
# File 'lib/prism/node.rb', line 14272 def deconstruct_keys(keys) { node_id: node_id, location: location, keyword_loc: keyword_loc, exceptions: exceptions, operator_loc: operator_loc, reference: reference, statements: statements, subsequent: subsequent } end |
#inspect ⇒ Object
def inspect -> String
14319 14320 14321 |
# File 'lib/prism/node.rb', line 14319 def inspect InspectVisitor.compose(self) end |
#keyword ⇒ Object
def keyword: () -> String
14309 14310 14311 |
# File 'lib/prism/node.rb', line 14309 def keyword keyword_loc.slice end |
#keyword_loc ⇒ Object
attr_reader keyword_loc: Location
14277 14278 14279 14280 14281 |
# File 'lib/prism/node.rb', line 14277 def keyword_loc location = @keyword_loc return location if location.is_a?(Location) @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end |
#operator ⇒ Object
def operator: () -> String?
14314 14315 14316 |
# File 'lib/prism/node.rb', line 14314 def operator operator_loc&.slice end |
#operator_loc ⇒ Object
attr_reader operator_loc: Location?
14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 |
# File 'lib/prism/node.rb', line 14287 def operator_loc location = @operator_loc case location when nil nil when Location location else @operator_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF) end end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
14324 14325 14326 |
# File 'lib/prism/node.rb', line 14324 def type :rescue_node end |