kit-contract edge

Array class
Kit::Contract::BuiltInContracts::Array
View Source

Enable Contracts on Array instances, and on elements at specific indeces.

Supported contract types:

  • of: alias of every_value, for types
  • with: run on the value of specific indeces (this is the default when using Hash[data])
  • at: here ordering matters
  • every: run on every value
  • instance: run on the hash instance itself
  • size: instance contract about size

Supported internal types of behaviour:

  • every_value: run on every value
  • index: run on value at index N
  • instance: run on the hash instance itself

Todo: add exemples.


Link to this section Summary ⚠️ Private APIs are currently hidden.


Link to this section Class methods 8

Convenience methods. They provide a slighly terser external API to instantiate contracts.


Link to this section Instance methods 10

Link to this method

#add_contract(contract:, safe: false)

View Source
Link to this method

#at(contracts, safe: false)

View Source

contract Hash.of(And[Integer, Gt[0]] => Contract)

Link to this method

#every(contract, safe: false)

View Source

contract Array.of(Contract).size(1)

Link to this method

#instance(contracts, safe: false)

View Source

contract Or[Contract, Array.of(Contract)]

Link to this method

#of(contract, safe: false)

View Source

contract Array.of(Contract).size(1)

Link to this method

#setup(*index_contracts)

View Source
Link to this method

#size(size, safe: true)

View Source

contract And[Integer, ->(x) { x > 0 }]

NOTE: this will only be useful when Organizer can handle any signature

Link to this method

#with(contracts, safe: false)

View Source

Position matters on this one contract Array.of(Contract)