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
Public Class Methods
Source
# File lib/contracts/builtin_contracts.rb, line 426 def initialize(contract_hash) super() @contract_hash = contract_hash end
Calls superclass method
Public Instance Methods
Source
# File lib/contracts/builtin_contracts.rb, line 431 def valid?(arg) return false unless arg.is_a?(Hash) return false unless arg.keys.sort.eql?(contract_hash.keys.sort) contract_hash.all? do |key, contract| contract_hash.key?(key) && Contract.valid?(arg[key], contract) end end