Class: RDL::Contract::AndContract

Inherits:
RDL::Contract show all
Defined in:
lib/rdl/contracts/and.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*contracts) ⇒ AndContract

Returns a new instance of AndContract.



5
6
7
# File 'lib/rdl/contracts/and.rb', line 5

def initialize(*contracts)
  @contracts = contracts
end

Instance Attribute Details

#contractsObject (readonly)

Returns the value of attribute contracts.



3
4
5
# File 'lib/rdl/contracts/and.rb', line 3

def contracts
  @contracts
end

Class Method Details

.array_to_s(a) ⇒ Object



25
26
27
# File 'lib/rdl/contracts/and.rb', line 25

def self.array_to_s(a)
  a.join(' && ')
end

.check_array(a, slf, *v, &blk) ⇒ Object

Check an array of contracts a

:slf:

is bound to self when the contracts are checked



16
17
18
19
# File 'lib/rdl/contracts/and.rb', line 16

def self.check_array(a, slf, *v, &blk)
  # All contracts must be satisfied
  a.all? { |c| c.check(slf, *v, &blk) }
end

Instance Method Details

#check(slf, *v, &blk) ⇒ Object

:slf:

is bound to self when the contracts are checked



10
11
12
# File 'lib/rdl/contracts/and.rb', line 10

def check(slf, *v, &blk)
  AndContract.check_array(@contracts, slf, *v, &blk)
end

#to_sObject



21
22
23
# File 'lib/rdl/contracts/and.rb', line 21

def to_s
  AndContract.array_to_s(@contracts)
end