Methods
#
C
D
E
F
K
M
N
R
S
T
U
V
W
Class Public methods
new(constructor = {})
    # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 23
23:     def initialize(constructor = {})
24:       if constructor.is_a?(Hash)
25:         super()
26:         update(constructor)
27:       else
28:         super(constructor)
29:       end
30:     end
new_from_hash_copying_default(hash)
    # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 40
40:     def self.new_from_hash_copying_default(hash)
41:       new(hash).tap do |new_hash|
42:         new_hash.default = hash.default
43:       end
44:     end
Instance Public 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 54
54:     def []=(key, value)
55:       regular_writer(convert_key(key), convert_value(value))
56:     end
convert_key(key)
     # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 152
152:       def convert_key(key)
153:         key.kind_of?(Symbol) ? key.to_s : key
154:       end
convert_value(value)
     # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 156
156:       def convert_value(value)
157:         if value.is_a? Hash
158:           value.nested_under_indifferent_access
159:         elsif value.is_a?(Array)
160:           value.dup.replace(value.map { |e| convert_value(e) })
161:         else
162:           value
163:         end
164:       end
default(key = nil)
    # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 32
32:     def default(key = nil)
33:       if key.is_a?(Symbol) && include?(key = key.to_s)
34:         self[key]
35:       else
36:         super
37:       end
38:     end
delete(key)

Removes a specified key from the hash.

     # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 136
136:     def delete(key)
137:       super(convert_key(key))
138:     end
dup()

Returns an exact copy of the hash.

     # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 113
113:     def dup
114:       self.class.new(self).tap do |new_hash|
115:         new_hash.default = default
116:       end
117:     end
extractable_options?()

Always returns true, so that Array#extract_options! finds members of this class.

    # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 11
11:     def extractable_options?
12:       true
13:     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 97
97:     def fetch(key, *extras)
98:       super(convert_key(key), *extras)
99:     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
    # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 88
88:     def key?(key)
89:       super(convert_key(key))
90:     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 121
121:     def merge(hash)
122:       self.dup.update(hash)
123:     end
nested_under_indifferent_access()
    # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 19
19:     def nested_under_indifferent_access
20:       self
21:     end
regular_writer(key, value)

Alias for #[]=

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 127
127:     def reverse_merge(other_hash)
128:       super self.class.new_from_hash_copying_default(other_hash)
129:     end
reverse_merge!(other_hash)
     # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 131
131:     def reverse_merge!(other_hash)
132:       replace(reverse_merge( other_hash ))
133:     end
stringify_keys()
     # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 141
141:     def stringify_keys; dup end
stringify_keys!()
     # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 140
140:     def stringify_keys!; self end
symbolize_keys()
     # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 143
143:     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 147
147:     def to_hash
148:       Hash.new(default).merge!(self)
149:     end
to_options!()
     # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 144
144:     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!"}
    # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 70
70:     def update(other_hash)
71:       if other_hash.is_a? HashWithIndifferentAccess
72:         super(other_hash)
73:       else
74:         other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
75:         self
76:       end
77:     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 108
108:     def values_at(*indices)
109:       indices.collect {|key| self[convert_key(key)]}
110:     end
with_indifferent_access()
    # File activesupport/lib/active_support/hash_with_indifferent_access.rb, line 15
15:     def with_indifferent_access
16:       dup
17:     end