Sha256: ccc23db5d2d457a897ce29f9a2681f93a091b2fb258e506625e927d4da4a7cf0
Contents?: true
Size: 892 Bytes
Versions: 62
Compression:
Stored size: 892 Bytes
Contents
# require "eitil_core/safe_executions/safe_rescue" Kernel.module_eval do # WORK IN PROCESS # => accept a second block, prefarabbly not as proc, with code to be exceuted in case of rescue # => or would it be possible to patch the 'rescue' keyword itself, so that we don't have to accept # blocks as arguments? def safe_rescue(error, &blk) unless blk raise ArgumentError, "a block should be passed" end unless error.is_a?(Class) or error.is_a?(String) raise ArgumentError, "the given 'error' should either be a constant or string" end if error.is_a?(Class) error_const = error elsif error.is_a?(String) and Object.const_defined?(error) error_const = error.constantize elsif error.is_a?(String) error_const = Object.const_set(error, Class.new(StandardError)) end blk.call rescue error_const end end
Version data entries
62 entries across 62 versions & 1 rubygems