Module | Hashie::Extensions::IndifferentAccess |
In: |
lib/hashie/extensions/indifferent_access.rb
|
IndifferentAccess gives you the ability to not care whether your hash has string or symbol keys. Made famous in Rails for accessing query and POST parameters, this is a handy tool for making sure your hash has maximum utility.
One unique feature of this mixin is that it will recursively inject itself into sub-hash instances without modifying the actual class of the sub-hash.
@example
class MyHash < Hash include Hashie::Extensions::MergeInitializer include Hashie::Extensions::IndifferentAccess end h = MyHash.new(:foo => 'bar', 'baz' => 'blip') h['foo'] # => 'bar' h[:foo] # => 'bar' h[:baz] # => 'blip' h['baz'] # => 'blip'
This will inject indifferent access into an instance of a hash without modifying the actual class. This is what allows IndifferentAccess to spread to sub-hashes.
Iterates through the keys and values, reconverting them to their proper indifferent state. Used when IndifferentAccess is injecting itself into member hashes.