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
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
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
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
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
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