Sha256: be0e29b593e3c0954fdbfab2b5522447d35d135aae4b6f2a9530b683ad0bf972

Contents?: true

Size: 1.56 KB

Versions: 195

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module RuboCop
  module AST
    # 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.
    class RescueNode < Node
      # Returns the body of the rescue node.
      #
      # @return [Node, nil] The body of the rescue node.
      def body
        node_parts[0]
      end

      # Returns an array of all the rescue branches in the exception handling statement.
      #
      # @return [Array<ResbodyNode>] an array of `resbody` nodes
      def resbody_branches
        node_parts[1...-1]
      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.
      def branches
        bodies = resbody_branches.map(&:body)
        bodies.push(else_branch) if else?
        bodies
      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.
      def else_branch
        node_parts[-1]
      end

      # Checks whether this exception handling statement has an `else` branch.
      #
      # @return [Boolean] whether the exception handling statement has an `else` branch
      def else?
        loc.else
      end
    end
  end
end

Version data entries

195 entries across 189 versions & 24 rubygems

Version Path
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-ast-1.38.0/lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.38.0 lib/rubocop/ast/node/rescue_node.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.31.3/lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.37.0 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.36.2 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.36.1 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.36.0 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.35.0 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.34.1 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.34.0 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.33.1 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.33.0 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.32.3 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.32.2 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.32.1 lib/rubocop/ast/node/rescue_node.rb
rubocop-ast-1.32.0 lib/rubocop/ast/node/rescue_node.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.31.3/lib/rubocop/ast/node/rescue_node.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/node/rescue_node.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/node/rescue_node.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-ast-1.23.0/lib/rubocop/ast/node/rescue_node.rb