Class: Contracts::Builtin::Not

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

Overview

Takes a variable number of contracts. The contract passes if all of those contracts fail for the given argument. Example: Not[nil]

Instance Method Summary collapse

Methods inherited from CallableClass

[]

Constructor Details

#initialize(*vals) ⇒ Not

Returns a new instance of Not.



270
271
272
273
# File 'lib/contracts/builtin_contracts.rb', line 270

def initialize(*vals)
  super()
  @vals = vals
end

Instance Method Details

#to_sObject



282
283
284
# File 'lib/contracts/builtin_contracts.rb', line 282

def to_s
  "a value that is none of #{@vals.inspect}"
end

#valid?(val) ⇒ Boolean

Returns:

  • (Boolean)


275
276
277
278
279
280
# File 'lib/contracts/builtin_contracts.rb', line 275

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