Class: Proc

Inherits:
Object
  • Object
show all
Defined in:
lib/handshake/block_contract.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contractObject

Returns the value of attribute contract.



2
3
4
# File 'lib/handshake/block_contract.rb', line 2

def contract
  @contract
end

Instance Method Details

#checked?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/handshake/block_contract.rb', line 11

def checked?
  not @contract.nil?
end

#checked_call(*args) ⇒ Object Also known as: call



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/handshake/block_contract.rb', line 15

def checked_call(*args)
  Handshake.catch_contract("Contract violated in call to proc #{self}") do
    @contract.check_accepts! *args
  end if checked?
  
  return_value = orig_call(*args)
  
  Handshake.catch_contract("Contract violated by proc #{self}") do
    @contract.check_returns! return_value
  end if checked?
  
  return_value
end