- #
- C
- D
- E
- F
- K
- M
- N
- R
- S
- T
- U
- V
- W
Assigns a new value to the hash:
hash = HashWithIndifferentAccess.new hash[:key] = "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
Removes a specified key from the hash.
Returns an exact copy of the hash.
Always returns true, so that Array#extract_options! finds members of this class.
Fetches the value for the specified key, same as doing hash[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
Merges the instantized and the specified hashes together, giving precedence to the values from the second hash. Does not overwrite the existing 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.
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
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"]