Class: Stannum::Contracts::IndifferentHashContract
- Inherits:
-
HashContract
- Object
- Stannum::Constraints::Base
- Base
- Stannum::Contract
- MapContract
- HashContract
- Stannum::Contracts::IndifferentHashContract
- Defined in:
- lib/stannum/contracts/indifferent_hash_contract.rb
Overview
An IndifferentHashContract defines constraints on an hash’s values.
The keys for an IndifferentHashContract must be either strings or symbols. The type of key is ignored when matching - a hash with a string key will match an expected symbol key and vice versa.
Direct Known Subclasses
Constant Summary
Constants inherited from Stannum::Constraints::Base
Stannum::Constraints::Base::NEGATED_TYPE, Stannum::Constraints::Base::TYPE
Instance Attribute Summary
Attributes inherited from Stannum::Constraints::Base
Instance Method Summary collapse
-
#initialize(allow_extra_keys: false, value_type: nil, **options, &block) ⇒ IndifferentHashContract
constructor
A new instance of IndifferentHashContract.
Methods inherited from HashContract
Methods inherited from MapContract
#add_key_constraint, #allow_extra_keys?, #expected_keys, #with_options
Methods inherited from Stannum::Contract
#add_constraint, #add_property_constraint
Methods inherited from Base
#==, #add_constraint, #concat, #does_not_match?, #each_constraint, #each_pair, #errors_for, #match, #matches?, #negated_errors_for, #negated_match
Methods inherited from Stannum::Constraints::Base
#==, #clone, #does_not_match?, #dup, #errors_for, #match, #matches?, #message, #negated_errors_for, #negated_match, #negated_message, #negated_type, #type, #with_options
Constructor Details
#initialize(allow_extra_keys: false, value_type: nil, **options, &block) ⇒ IndifferentHashContract
Returns a new instance of IndifferentHashContract.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/stannum/contracts/indifferent_hash_contract.rb', line 48 def initialize( allow_extra_keys: false, value_type: nil, **, &block ) super( allow_extra_keys: allow_extra_keys, key_type: Stannum::Constraints::Hashes::IndifferentKey.new, value_type: value_type, **, &block ) end |