123456789_123456789_123456789_123456789_123456789_

Class: Prism::RescueNode

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PrismNode
Instance Chain:
self, PrismNode
Inherits: PrismNode
Defined in: lib/prism/node.rb,
ext/prism/api_node.c,
lib/prism/node_ext.rb

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 exception field.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, consequent) ⇒ RescueNode

Initialize a new RescueNode node.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13937

def initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, consequent)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @exceptions = exceptions
  @operator_loc = operator_loc
  @reference = reference
  @statements = statements
  @consequent = consequent
end

Class Method Details

.type

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 14037

def self.type
  :rescue_node
end

Instance Attribute Details

#consequent (readonly)

Returns the subsequent rescue clause of the rescue node. This method is deprecated in favor of #subsequent.

[ GitHub ]

  
# File 'lib/prism/node_ext.rb', line 497

attr_reader :consequent

#exceptions (readonly)

attr_reader exceptions: Array

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13996

attr_reader :exceptions

#reference (readonly)

attr_reader reference: Prism.node?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 14011

attr_reader :reference

#statements (readonly)

attr_reader statements: StatementsNode?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 14013

attr_reader :statements

Instance Method Details

#===(other)

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 14043

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) &&
    (consequent === other.consequent)
end

#accept(visitor)

def accept: (Visitor visitor) -> void

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13951

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

#child_nodes Also known as: #deconstruct

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13956

def child_nodes
  [*exceptions, reference, statements, consequent]
end

#comment_targets

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13971

def comment_targets
  [keyword_loc, *exceptions, *operator_loc, *reference, *statements, *consequent] #: Array[Prism::node | Location]
end

#compact_child_nodes

def compact_child_nodes: () -> Array

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13961

def compact_child_nodes
  compact = [] #: Array[Prism::node]
  compact.concat(exceptions)
  compact << reference if reference
  compact << statements if statements
  compact << consequent if consequent
  compact
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, consequent: self.consequent)

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?keyword_loc: Location, ?exceptions: Array, ?operator_loc: Location?, ?reference: Prism.node?, ?statements: StatementsNode?, ?consequent: RescueNode?) -> RescueNode

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13976

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, consequent: self.consequent)
  RescueNode.new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, statements, consequent)
end

#deconstruct

Alias for #child_nodes.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13981

alias deconstruct child_nodes

#deconstruct_keys(keys)

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, keyword_loc: Location, exceptions: Array, operator_loc: Location?, reference: Prism.node?, statements: StatementsNode?, consequent: RescueNode? }

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13984

def deconstruct_keys(keys)
  { node_id: node_id, location: location, keyword_loc: keyword_loc, exceptions: exceptions, operator_loc: operator_loc, reference: reference, statements: statements, consequent: consequent }
end

#inspect

def inspect -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 14027

def inspect
  InspectVisitor.compose(self)
end

#keyword

def keyword: () -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 14017

def keyword
  keyword_loc.slice
end

#keyword_loc

attr_reader keyword_loc: Location

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13989

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

#operator

def operator: () -> String?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 14022

def operator
  operator_loc&.slice
end

#operator_loc

attr_reader operator_loc: Location?

[ GitHub ]

  
# File 'lib/prism/node.rb', line 13998

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

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 14032

def type
  :rescue_node
end