Sha256: 0735865044580da4503ac5ae7b8a402c190ef6efb002e88ca30744fc326f2422

Contents?: true

Size: 864 Bytes

Versions: 5

Compression:

Stored size: 864 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module AST
    # A node extension for `resbody` nodes. This will be used in place of a
    # plain node when the builder constructs the AST, making its methods
    # available to all `resbody` nodes within RuboCop.
    class ResbodyNode < Node
      # Returns the body of the `rescue` clause.
      #
      # @return [Node, nil] The body of the `resbody`.
      def body
        node_parts[2]
      end

      # Returns the exception variable of the `rescue` clause.
      #
      # @return [Node, nil] The exception variable of the `resbody`.
      def exception_variable
        variable = node_parts[1]
        return variable if variable

        # When resbody is an implicit rescue (i.e. `rescue e` style),
        # the exception variable is descendants[1].
        descendants[1]
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.71.0 lib/rubocop/ast/node/resbody_node.rb
rubocop-0.70.0 lib/rubocop/ast/node/resbody_node.rb
rubocop-0.69.0 lib/rubocop/ast/node/resbody_node.rb
rubocop-0.68.1 lib/rubocop/ast/node/resbody_node.rb
rubocop-0.68.0 lib/rubocop/ast/node/resbody_node.rb