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
Calls superclass method
# File lib/contracts/builtin_contracts.rb, line 426 def initialize(contract_hash) super() @contract_hash = contract_hash end
Public Instance Methods
valid?(arg)
click to toggle 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