Class: Contracts::Builtin::And

Inherits:
CallableClass show all
Defined in:
lib/contracts/builtin_contracts.rb

Overview

Takes a variable number of contracts. The contract passes if all contracts pass. Example: And[Fixnum, Float]

Instance Method Summary collapse

Methods inherited from CallableClass

[]

Constructor Details

#initialize(*vals) ⇒ And

Returns a new instance of And.



144
145
146
# File 'lib/contracts/builtin_contracts.rb', line 144

def initialize(*vals)
  @vals = vals
end

Instance Method Details

#to_sObject



155
156
157
# File 'lib/contracts/builtin_contracts.rb', line 155

def to_s
  EnumInspector.inspect(@vals, "and")
end

#valid?(val) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
151
152
153
# File 'lib/contracts/builtin_contracts.rb', line 148

def valid?(val)
  @vals.all? do |contract|
    res, = Contract.valid?(val, contract)
    res
  end
end