module Bang::ProcMixin
Mixin for Proc
class that adds ‘#raises?`, `#rescues?` and `#throws?`.
Public Instance Methods
raises?(exception)
click to toggle source
Execute this procedure and return ‘true` if the specific given `exception` is raised, otherwise `false`.
@return [true,false] Whether exception was raised.
# File lib/bang.rb, line 258 def raises?(exception) begin call false rescue exception => err exception == err.class rescue Exception => err false end end
rescues?(exception)
click to toggle source
Execute this procedure and return ‘true` if the given `exception`, or subclass there-of is raised, otherwise `false`.
@return [true,false] Whether exception was rescued.
# File lib/bang.rb, line 275 def rescues?(exception) begin call false rescue exception => err true rescue Exception => err false end end
throws?(object)
click to toggle source
Execute this procedure and return ‘true` if the given `object`, is thrown, otherwise `false`.
@return [true,false] Whether object was thrown.
# File lib/bang.rb, line 292 def throws?(object) pass = true catch(object) do begin call rescue ArgumentError => err # 1.9 exception #msg += ", not #{err.message.split(/ /).last}" rescue NameError => err # 1.8 exception #msg += ", not #{err.name.inspect}" end pass = false end pass end