module Nuggets::Object::RescueIfMixin
Public Instance Methods
rescue_if([args]) { |err| ... }
click to toggle source
Rescue exceptions matching args
, or StandardError if not given, if block
returns true.
# File lib/nuggets/object/rescue_if_mixin.rb 36 def rescue_if(*args, &block) 37 raise ::ArgumentError, 'no block given' unless block 38 39 args = [::StandardError] if args.empty? 40 41 ::Module.new { 42 define_singleton_method(:===) { |err| 43 block[err] if args.any? { |arg| arg === err } 44 } 45 } 46 end
rescue_unless([args]) { |err| ... }
click to toggle source
Rescue exceptions matching args
, or StandardError if not given, unless block
returns true.
# File lib/nuggets/object/rescue_if_mixin.rb 53 def rescue_unless(*args, &block) 54 raise ::ArgumentError, 'no block given' unless block 55 56 rescue_if(*args) { |err| !block[err] } 57 end