Class: Proc
Overview
Instance Method Summary collapse
-
#raises_error?(*args) ⇒ Boolean
The
#raises_error?
method checks whether an exception is raised when the calling Proc is called with the given *args.
Instance Method Details
#raises_error?(*args) ⇒ Boolean
The #raises_error?
method checks whether an exception is raised when the calling Proc is called with the given *args.
The #raises_error?
method does not actually create lasting changes to objects or variables; it only checks whether an exception would be raised if the Proc were called with the given *args.
Basic examples:
proc = Proc.new {|q| 1.quo(q) }
proc.raises_error?(2) # => false
proc.raises_error?(0) # => true
Examples with destructive proc:
hash = {:foo => :bar}
proc = Proc.new {|hash| hash.reject! {|k,v| k === :foo } }
proc.raises_error?(hash) # => false
hash # => {:foo => :bar}
32 33 34 |
# File 'lib/reactive_extensions/proc/errors.rb', line 32 def raises_error?(*args) (!self.call(*args.deep_dup)) rescue true end |