class Contracts::Builtin::StrictHash

Use this to specify the Hash characteristics. This contracts fails if there are any extra keys that don't have contracts on them. Example: StrictHash[{ a: String, b: Bool }]

Attributes

contract_hash[R]

Public Class Methods

new(contract_hash) click to toggle source
# File lib/contracts/builtin_contracts.rb, line 402
def initialize(contract_hash)
  @contract_hash = contract_hash
end

Public Instance Methods

valid?(arg) click to toggle source
# File lib/contracts/builtin_contracts.rb, line 406
def valid?(arg)
  return false unless arg.is_a?(Hash)

  contract_hash.all? do |key, _v|
    contract_hash.key?(key) && Contract.valid?(arg[key], contract_hash[key])
  end
end