ScampiSourceProc

class Proc

Definitions

def raise?(*exceptions)

Call the proc and check whether it raises one of the given exceptions.

Signature

parameter exceptions Array(Class)

Exception classes to catch (defaults to RuntimeError).

returns Exception | Boolean

The caught exception, or false if none was raised.

Implementation

def raise?(*exceptions)
  call
rescue *(exceptions.empty? ? RuntimeError : exceptions) => e
  e
else
  false
end

def throw?(sym)

Call the proc and check whether it throws the given symbol.

Signature

parameter sym Symbol

The symbol to catch.

returns Boolean

Implementation

def throw?(sym)
  catch(sym) {
    call
    return false
  }
  return true
end

def change?

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

Signature

returns Boolean

Implementation

def change?
  pre_result = yield
  call
  post_result = yield
  pre_result != post_result
end