BuiltInContracts
module
Kit::Contract::BuiltInContracts
View Source
This module contains some Built-in Contracts
The easiest way to use them is to include Kit::Contract::BuiltInContracts in your class/module.
- Basic types
Any: succeeds for any argument.Array: ensure that the argument is an::Array. Index based constraints can also be expressed. See Array doc.Args: variation of Array that lets you define contract for positional arguments.BigDecimal: ensure that the argument is a::BigDecimal.Boolean: ensure that the argument istrueorfalse.Complex: ensure that the argument is a::Complex.FalseClass: ensure that the argument is a::FalseClass.Float: ensure that the argument is a::Float.Hash: ensure that the argument is a::Hash. Key based constraints can also be expressed. See Hash doc.Integer: ensure that the argument is a::Integer.Numeric: ensure that the argument is a::Numeric.Rational: ensure that the argument is a::Rational.String: ensure that the argument is a::String.Symbol: ensure that the argument is a::Symbol.TrueClass: ensure that the argument is a::TrueClass.Tupple: variation ofArraywith an implicit check on size.
- Operations
And: ensure all contracts are successfulOptional: ensure that if there is a value, it it not nilOr: ensure at least one contract is successful
- Dependent types
Callable: alias ofRespondTo[:call]Enum: alias ofInEq: ensure that the argument equals the given valueIn: ensure the argument is part of a given collection of objects / valuesNotEq: ensure that the argument does not equal the given valueNotIn: ensure that the argument is not part of a given collection of objects / valuesRespondTo: ensure that the objectrespond_to?a specific method
Link to this section Summary ⚠️ Private APIs are currently hidden.
Modules 2
Classes 16
Constants 20
Link to this section Constants 20
Ensure that the argument is a ::BigDecimal.
IsA[::BigDecimal]
Ensure that the argument is true or false.
Or[IsA[::TrueClass], IsA[::FalseClass]
Ensure the argument respond_to(:call)
RespondTo[:call]
Ensure the argument is an Array of Callable
Array.of(Callable)
Ensure that the argument is a ::Complex.
IsA[::Complex]
Ensure that the argument is a ::FalseClass.
IsA[::FalseClass]
Ensure that the argument is a ::Float.
IsA[::Float]
Integer
Ensure that the argument is an ::Integer.
IsA[::Integer]
NegativeInteger
Ensure that the Contract argument is a negative ::Integer.
And[Integer, ->(size) { size < 0 }]
Eq[nil].named('Nil')
NotEq[nil].named('NonNil')
Ensure that the argument is a ::Numeric.
IsA[::Numeric]
PositiveInteger
Ensure that the Contract argument is a positive ::Integer.
And[Integer, ->(size) { size > 0 }]
Ensure that the argument is a ::Rational.
IsA[::Rational]
Ensure that the argument is a ::String.
IsA[::String]
Ensure that the argument is a ::Symbol.
IsA[::Symbol]
Ensure that the argument is a ::TrueClass.
IsA[::TrueClass]