- #
- C
- D
- E
- F
- H
- I
- K
- M
- N
- R
- S
- T
- U
- V
- W
Assigns a new value to the hash:
hash = HashWithIndifferentAccess.new hash[:key] = "value"
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.
Same as Hash#fetch
where the key passed as argument can be
either a string or a symbol:
counters = HashWithIndifferentAccess.new counters[:foo] = 1 counters.fetch("foo") # => 1 counters.fetch(:bar, 0) # => 0 counters.fetch(:bar) {|key| 0} # => 0 counters.fetch(:zoo) # => KeyError: key not found: "zoo"
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 def update(other_hash) if other_hash.is_a? HashWithIndifferentAccess super(other_hash) else other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } self end 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"]