module Augmented::Procs::Rescuable

Constants

NOT_PROVIDED

Public Instance Methods

rescues(exception_class, return_value = NOT_PROVIDED, &block) click to toggle source
# File lib/augmented/procs/rescuable.rb, line 8
def rescues exception_class, return_value = NOT_PROVIDED, &block
  raise ArgumentError, 'must provide a return value or block' if return_value == NOT_PROVIDED && !block_given?

  original = self

  Proc.new do |*args|
    begin
      original.call(*args)
    rescue exception_class => exception
      block ? block.call(exception) : return_value
    end
  end
end