Class: Proc
Instance Method Summary collapse
-
#change? ⇒ Boolean
Call the proc and check whether it changes the result of the given block.
-
#raise?(*exceptions) ⇒ Boolean
Call the proc and check whether it raises one of the given exceptions.
-
#throw?(sym) ⇒ Boolean
Call the proc and check whether it throws the given symbol.
Instance Method Details
#change? ⇒ Boolean
Call the proc and check whether it changes the result of the given block.
48 49 50 51 52 53 |
# File 'lib/scampi/monkey_patches.rb', line 48 def change? pre_result = yield call post_result = yield pre_result != post_result end |
#raise?(*exceptions) ⇒ Boolean
Call the proc and check whether it raises one of the given exceptions.
25 26 27 28 29 30 31 |
# File 'lib/scampi/monkey_patches.rb', line 25 def raise?(*exceptions) call rescue *(exceptions.empty? ? RuntimeError : exceptions) => e e else false end |
#throw?(sym) ⇒ Boolean
Call the proc and check whether it throws the given symbol.
37 38 39 40 41 42 43 |
# File 'lib/scampi/monkey_patches.rb', line 37 def throw?(sym) catch(sym) { call return false } return true end |