Type:
Class

Implements a hash where keys :foo and "foo" are considered to be the same.

rgb = ActiveSupport::HashWithIndifferentAccess.new

rgb[:black] = '#000000'
rgb[:black]  # => '#000000'
rgb['black'] # => '#000000'

rgb['white'] = '#FFFFFF'
rgb[:white]  # => '#FFFFFF'
rgb['white'] # => '#FFFFFF'

Internally symbols are mapped to strings when used as keys in the entire writing interface (calling []=, merge, etc). This mapping belongs to the public interface. For example, given:

hash = ActiveSupport::HashWithIndifferentAccess.new(a: 1)

You are guaranteed that the key is returned as a string:

hash.keys # => ["a"]

Technically other types of keys are accepted:

hash = ActiveSupport::HashWithIndifferentAccess.new(a: 1)
hash[0] = 0
hash # => {"a"=>1, 0=>0}

but this class is intended for use cases where strings or symbols are the expected keys and it is convenient to understand both as the same. For example the params hash in Ruby on Rails.

Note that core extensions define Hash#with_indifferent_access:

rgb = { black: '#000000', white: '#FFFFFF' }.with_indifferent_access

which may be handy.

convert_value

convert_value(value, options = {}) Instance Protected methods

2015-06-20 00:00:00
dup

dup() Instance Public methods Returns an exact copy of the hash.

2015-06-20 00:00:00
extractable_options?

extractable_options?() Instance Public methods Returns true so

2015-06-20 00:00:00
reject

reject(*args, &block) Instance Public methods

2015-06-20 00:00:00
reverse_merge!

reverse_merge!(other_hash) Instance Public methods Same semantics as

2015-06-20 00:00:00
store

store(key, value) Instance Public methods Alias for:

2015-06-20 00:00:00
delete

delete(key) Instance Public methods Removes the specified key from the hash

2015-06-20 00:00:00