Methods
Public Class methods
new(constructor = {})
      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 13
13:     def initialize(constructor = {})
14:       if constructor.is_a?(Hash)
15:         super()
16:         update(constructor)
17:       else
18:         super(constructor)
19:       end
20:     end
new_from_hash_copying_default(hash)
      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 30
30:     def self.new_from_hash_copying_default(hash)
31:       ActiveSupport::HashWithIndifferentAccess.new(hash).tap do |new_hash|
32:         new_hash.default = hash.default
33:       end
34:     end
Public Instance methods
[]=(key, value)

Assigns a new value to the hash:

  hash = HashWithIndifferentAccess.new
  hash[:key] = "value"
This method is also aliased as regular_writer
      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 44
44:     def []=(key, value)
45:       regular_writer(convert_key(key), convert_value(value))
46:     end
default(key = nil)
      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 22
22:     def default(key = nil)
23:       if key.is_a?(Symbol) && include?(key = key.to_s)
24:         self[key]
25:       else
26:         super
27:       end
28:     end
delete(key)

Removes a specified key from the hash.

       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 118
118:     def delete(key)
119:       super(convert_key(key))
120:     end
dup()

Returns an exact copy of the hash.

      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 97
97:     def dup
98:       HashWithIndifferentAccess.new(self)
99:     end
extractable_options?()
      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 9
 9:     def extractable_options?
10:       true
11:     end
fetch(key, *extras)

Fetches the value for the specified key, same as doing hash[key]

      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 81
81:     def fetch(key, *extras)
82:       super(convert_key(key), *extras)
83:     end
key?(key)

Checks the hash for a key matching the argument passed in:

  hash = HashWithIndifferentAccess.new
  hash["key"] = "value"
  hash.key? :key  # => true
  hash.key? "key" # => true
This method is also aliased as include? has_key? member?
      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 72
72:     def key?(key)
73:       super(convert_key(key))
74:     end
merge(hash)

Merges the instantized and the specified hashes together, giving precedence to the values from the second hash Does not overwrite the existing hash.

       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 103
103:     def merge(hash)
104:       self.dup.update(hash)
105:     end
reverse_merge(other_hash)

Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second. This overloaded definition prevents returning a regular hash, if reverse_merge is called on a HashWithDifferentAccess.

       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 109
109:     def reverse_merge(other_hash)
110:       super self.class.new_from_hash_copying_default(other_hash)
111:     end
reverse_merge!(other_hash)
       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 113
113:     def reverse_merge!(other_hash)
114:       replace(reverse_merge( other_hash ))
115:     end
stringify_keys()
       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 123
123:     def stringify_keys; dup end
stringify_keys!()
       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 122
122:     def stringify_keys!; self end
symbolize_keys()
       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 125
125:     def symbolize_keys; to_hash.symbolize_keys end
to_hash()

Convert to a Hash with String keys.

       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 129
129:     def to_hash
130:       Hash.new(default).merge!(self)
131:     end
to_options!()
       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 126
126:     def to_options!; self end
update(other_hash)

Updates the instantized hash with values from the second:

  hash_1 = HashWithIndifferentAccess.new
  hash_1[:key] = "value"

  hash_2 = HashWithIndifferentAccess.new
  hash_2[:key] = "New Value!"

  hash_1.update(hash_2) # => {"key"=>"New Value!"}
This method is also aliased as regular_update merge!
      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 58
58:     def update(other_hash)
59:       other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
60:       self
61:     end
values_at(*indices)

Returns an array of the values at the specified indices:

  hash = HashWithIndifferentAccess.new
  hash[:a] = "x"
  hash[:b] = "y"
  hash.values_at("a", "b") # => ["x", "y"]
      # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 92
92:     def values_at(*indices)
93:       indices.collect {|key| self[convert_key(key)]}
94:     end
Protected Instance methods
convert_key(key)
       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 134
134:       def convert_key(key)
135:         key.kind_of?(Symbol) ? key.to_s : key
136:       end
convert_value(value)
       # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 138
138:       def convert_value(value)
139:         case value
140:         when Hash
141:           self.class.new_from_hash_copying_default(value)
142:         when Array
143:           value.collect { |e| e.is_a?(Hash) ? self.class.new_from_hash_copying_default(e) : e }
144:         else
145:           value
146:         end
147:       end