Module: Contract

Defined in:
lib/contract.rb

Overview

Provides a way to define contracts for a given function. The methods ‘define` and `verify` can be used directly. If the `Contract` module is included in a class, the methods `contract` and `verify` are added.

Class Method Summary collapse

Class Method Details

.contractObject

Returns the value of the block if all verifications pass



9
10
11
12
13
# File 'lib/contract.rb', line 9

def contract
  catch(:contract) do
    yield
  end
end

.verify(value) ⇒ Object

Fails unless value is true



16
17
18
# File 'lib/contract.rb', line 16

def verify(value)
  value || throw(:contract, false)
end