Sha256: e9ed31a5ca4605d04990d8e399cf5a65cdd39ce7c3ffb55bee3db3fd0c627809

Contents?: true

Size: 783 Bytes

Versions: 2

Compression:

Stored size: 783 Bytes

Contents

# encoding: utf-8

module Rubymisc
  module Exceptional
    ##
    # @example
    #   begin
    #     raise 'Timeout socket'
    #   rescue errors_with_message /socket/
    #     p 'socket E'
    #   end
    #
    def errors_with_message(pattern)
      m = Module.new
      (class << m; self; end).instance_eval do
        define_method(:===) { |e| pattern === e.message }
      end
      m
    end

    ##
    # @example
    #   rescue => e; raise NestedException.new('Error B', e); end
    #   rescue; raise NestedException, 'Error B'; end
    #
    class NestedException < StandardError
      attr :original

      def initialize(msg, original = $!)
        super(msg)
        @original = original
      end
    end
  end
end

::Object.module_eval 'include Rubymisc::Exceptional'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubymisc-0.2.0 lib/rubymisc/exceptional.rb
rubymisc-0.1.0 lib/rubymisc/exceptional.rb