class RuboCop::AST::RescueNode

A node extension for `rescue` nodes. This will be used in place of a plain node when the builder constructs the AST, making its methods available to all `rescue` nodes within RuboCop.

Public Instance Methods

body() click to toggle source

Returns the body of the rescue node.

@return [Node, nil] The body of the rescue node.

# File lib/rubocop/ast/node/rescue_node.rb, line 12
def body
  node_parts[0]
end
branches() click to toggle source

Returns an array of all the rescue branches in the exception handling statement.

@return [Array<Node, nil>] an array of the bodies of the rescue branches and the else (if any). Note that these bodies could be nil.

# File lib/rubocop/ast/node/rescue_node.rb, line 27
def branches
  bodies = resbody_branches.map(&:body)
  bodies.push(else_branch) if else?
  bodies
end
else?() click to toggle source

Checks whether this exception handling statement has an `else` branch.

@return [Boolean] whether the exception handling statement has an `else` branch

# File lib/rubocop/ast/node/rescue_node.rb, line 44
def else?
  loc.else
end
else_branch() click to toggle source

Returns the else branch of the exception handling statement, if any.

@return [Node] the else branch node of the exception handling statement @return [nil] if the exception handling statement does not have an else branch.

# File lib/rubocop/ast/node/rescue_node.rb, line 37
def else_branch
  node_parts[-1]
end
resbody_branches() click to toggle source

Returns an array of all the rescue branches in the exception handling statement.

@return [Array<ResbodyNode>] an array of `resbody` nodes

# File lib/rubocop/ast/node/rescue_node.rb, line 19
def resbody_branches
  node_parts[1...-1]
end