Class: Handshake::CheckedProc
- Inherits:
-
Proc
- Object
- Proc
- Handshake::CheckedProc
- Defined in:
- lib/handshake/block_contract.rb
Instance Attribute Summary collapse
-
#contract ⇒ Object
Returns the value of attribute contract.
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #checked? ⇒ Boolean
-
#initialize(contract, &block) ⇒ CheckedProc
constructor
A new instance of CheckedProc.
Constructor Details
#initialize(contract, &block) ⇒ CheckedProc
Returns a new instance of CheckedProc.
5 6 7 8 |
# File 'lib/handshake/block_contract.rb', line 5 def initialize(contract, &block) @contract = contract super(&block) end |
Instance Attribute Details
#contract ⇒ Object
Returns the value of attribute contract.
3 4 5 |
# File 'lib/handshake/block_contract.rb', line 3 def contract @contract end |
Instance Method Details
#call(*args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/handshake/block_contract.rb', line 14 def call(*args) Handshake.catch_contract("Contract violated in call to proc #{self}") do @contract.check_accepts!(*args) end if checked? return_value = super(*args) Handshake.catch_contract("Contract violated by proc #{self}") do @contract.check_returns! return_value end if checked? return_value end |
#checked? ⇒ Boolean
10 11 12 |
# File 'lib/handshake/block_contract.rb', line 10 def checked? not @contract.nil? end |