Class: Contracts::Constraints::HashOf

Inherits:
Base
  • Object
show all
Defined in:
lib/contracts.rb

Instance Method Summary collapse

Methods inherited from Base

#to_h

Constructor Details

#initialize(key, value) ⇒ HashOf

Returns a new instance of HashOf.



258
259
260
261
# File 'lib/contracts.rb', line 258

def initialize(key, value)
  (@key = Constraints.coerce(key)
   @value = Constraints.coerce(value))
end

Instance Method Details

#descriptionObject



264
# File 'lib/contracts.rb', line 264

def description = "Hash<#{@key.description}, #{@value.description}>"

#matches?(value) ⇒ Boolean

Returns:

  • (Boolean)


263
# File 'lib/contracts.rb', line 263

def matches?(value) = value.is_a?(Hash) && value.all? { |k, v| @key.matches?(k) && @value.matches?(v) }