class Prism::RescueNode

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.

Attributes

exceptions[R]

attr_reader exceptions: Array

statements[R]

attr_reader statements: StatementsNode?

subsequent[R]

attr_reader subsequent: RescueNode?

Public Class Methods

new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent) click to toggle source

Initialize a new RescueNode node.

# File lib/prism/node.rb, line 16876
def initialize(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @keyword_loc = keyword_loc
  @exceptions = exceptions
  @operator_loc = operator_loc
  @reference = reference
  @then_keyword_loc = then_keyword_loc
  @statements = statements
  @subsequent = subsequent
end
type() click to toggle source

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

# File lib/prism/node.rb, line 17027
def self.type
  :rescue_node
end

Public Instance Methods

===(other) click to toggle source

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

# File lib/prism/node.rb, line 17033
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) &&
    (then_keyword_loc.nil? == other.then_keyword_loc.nil?) &&
    (statements === other.statements) &&
    (subsequent === other.subsequent)
end
accept(visitor) click to toggle source

def accept: (Visitor visitor) -> void

# File lib/prism/node.rb, line 16891
def accept(visitor)
  visitor.visit_rescue_node(self)
end
child_nodes() click to toggle source

def child_nodes: () -> Array

# File lib/prism/node.rb, line 16896
def child_nodes
  [*exceptions, reference, statements, subsequent]
end
Also aliased as: deconstruct
comment_targets() click to toggle source

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

# File lib/prism/node.rb, line 16921
def comment_targets
  [keyword_loc, *exceptions, *operator_loc, *reference, *then_keyword_loc, *statements, *subsequent] #: Array[Prism::node | Location]
end
compact_child_nodes() click to toggle source

def compact_child_nodes: () -> Array

# File lib/prism/node.rb, line 16911
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() click to toggle source

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

# File lib/prism/node_ext.rb, line 497
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, then_keyword_loc: self.then_keyword_loc, statements: self.statements, subsequent: self.subsequent) click to toggle source

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, ?then_keyword_loc: Location?, ?statements: StatementsNode?, ?subsequent: RescueNode?) -> RescueNode

# File lib/prism/node.rb, line 16926
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, then_keyword_loc: self.then_keyword_loc, statements: self.statements, subsequent: self.subsequent)
  RescueNode.new(source, node_id, location, flags, keyword_loc, exceptions, operator_loc, reference, then_keyword_loc, statements, subsequent)
end
deconstruct()

def deconstruct: () -> Array

Alias for: child_nodes
deconstruct_keys(keys) click to toggle source

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, then_keyword_loc: Location?, statements: StatementsNode?, subsequent: RescueNode? }

# File lib/prism/node.rb, line 16934
def deconstruct_keys(keys)
  { node_id: node_id, location: location, keyword_loc: keyword_loc, exceptions: exceptions, operator_loc: operator_loc, reference: reference, then_keyword_loc: then_keyword_loc, statements: statements, subsequent: subsequent }
end
each_child_node() { |node| ... } click to toggle source

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

# File lib/prism/node.rb, line 16901
def each_child_node
  return to_enum(:each_child_node) unless block_given?

  exceptions.each { |node| yield node }
  yield reference if reference
  yield statements if statements
  yield subsequent if subsequent
end
inspect() click to toggle source

def inspect -> String

# File lib/prism/node.rb, line 17017
def inspect
  InspectVisitor.compose(self)
end
keyword() click to toggle source

def keyword: () -> String

# File lib/prism/node.rb, line 17002
def keyword
  keyword_loc.slice
end
keyword_loc() click to toggle source

attr_reader keyword_loc: Location

# File lib/prism/node.rb, line 16939
def keyword_loc
  location = @keyword_loc
  return location if location.is_a?(Location)
  @keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
end
operator() click to toggle source

def operator: () -> String?

# File lib/prism/node.rb, line 17007
def operator
  operator_loc&.slice
end
operator_loc() click to toggle source

attr_reader operator_loc: Location?

# File lib/prism/node.rb, line 16955
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
save_keyword_loc(repository) click to toggle source

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

# File lib/prism/node.rb, line 16947
def save_keyword_loc(repository)
  repository.enter(node_id, :keyword_loc)
end
save_operator_loc(repository) click to toggle source

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

# File lib/prism/node.rb, line 16969
def save_operator_loc(repository)
  repository.enter(node_id, :operator_loc) unless @operator_loc.nil?
end
save_then_keyword_loc(repository) click to toggle source

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

# File lib/prism/node.rb, line 16991
def save_then_keyword_loc(repository)
  repository.enter(node_id, :then_keyword_loc) unless @then_keyword_loc.nil?
end
then_keyword() click to toggle source

def then_keyword: () -> String?

# File lib/prism/node.rb, line 17012
def then_keyword
  then_keyword_loc&.slice
end
then_keyword_loc() click to toggle source

attr_reader then_keyword_loc: Location?

# File lib/prism/node.rb, line 16977
def then_keyword_loc
  location = @then_keyword_loc
  case location
  when nil
    nil
  when Location
    location
  else
    @then_keyword_loc = Location.new(source, location >> 32, location & 0xFFFFFFFF)
  end
end
type() click to toggle source

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

# File lib/prism/node.rb, line 17022
def type
  :rescue_node
end