class Rtype::Behavior::TypedHash
Typed hash behavior. empty hash allowed
Public Class Methods
new(key_type, value_type)
click to toggle source
# File lib/rtype/behavior/typed_hash.rb, line 5 def initialize(key_type, value_type) @ktype = key_type @vtype = value_type Rtype.assert_valid_argument_type_sig_element(@ktype) Rtype.assert_valid_argument_type_sig_element(@vtype) end
Public Instance Methods
error_message(value)
click to toggle source
# File lib/rtype/behavior/typed_hash.rb, line 24 def error_message(value) "Expected #{value.inspect} to be a hash with key type #{@ktype.inspect} and value type #{@vtype.inspect}" end
valid?(value)
click to toggle source
# File lib/rtype/behavior/typed_hash.rb, line 12 def valid?(value) if value.is_a?(Hash) any = value.any? do |k, v| !Rtype::valid?(@ktype, k) || !Rtype::valid?(@vtype, v) end !any else false end end