Class: Proc

Inherits:
Object show all
Defined in:
lib/scampi/monkey_patches.rb

Instance Method Summary collapse

Instance Method Details

#change?Boolean

Call the proc and check whether it changes the result of the given block.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


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