Hash
Assigns a new value to the hash:
hash = HashWithIndifferentAccess.new hash[:key] = "value"
# File lib/mail/indifferent_hash.rb, line 40 40: def []=(key, value) 41: regular_writer(convert_key(key), convert_value(value)) 42: end
# File lib/mail/indifferent_hash.rb, line 18 18: def default(key = nil) 19: if key.is_a?(Symbol) && include?(key = key.to_s) 20: self[key] 21: else 22: super 23: end 24: end
Removes a specified key from the hash.
# File lib/mail/indifferent_hash.rb, line 116 116: def delete(key) 117: super(convert_key(key)) 118: end
Returns an exact copy of the hash.
# File lib/mail/indifferent_hash.rb, line 95 95: def dup 96: IndifferentHash.new(self) 97: end
Fetches the value for the specified key, same as doing hash[key]
# File lib/mail/indifferent_hash.rb, line 79 79: def fetch(key, *extras) 80: super(convert_key(key), *extras) 81: end
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 lib/mail/indifferent_hash.rb, line 70 70: def key?(key) 71: super(convert_key(key)) 72: end
Merges the instantized and the specified hashes together, giving precedence to the values from the second hash Does not overwrite the existing hash.
# File lib/mail/indifferent_hash.rb, line 101 101: def merge(hash) 102: self.dup.update(hash) 103: end
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 lib/mail/indifferent_hash.rb, line 107 107: def reverse_merge(other_hash) 108: super self.class.new_from_hash_copying_default(other_hash) 109: end
# File lib/mail/indifferent_hash.rb, line 111 111: def reverse_merge!(other_hash) 112: replace(reverse_merge( other_hash )) 113: end
# File lib/mail/indifferent_hash.rb, line 121 121: def stringify_keys; dup end
# File lib/mail/indifferent_hash.rb, line 120 120: def stringify_keys!; self end
# File lib/mail/indifferent_hash.rb, line 122 122: def symbolize_keys; to_hash.symbolize_keys end
# File lib/mail/indifferent_hash.rb, line 125 125: def to_hash 126: Hash.new(default).merge!(self) 127: end
# File lib/mail/indifferent_hash.rb, line 123 123: def to_options!; self end
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 lib/mail/indifferent_hash.rb, line 56 56: def update(other_hash) 57: other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) } 58: self 59: 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"]
# File lib/mail/indifferent_hash.rb, line 90 90: def values_at(*indices) 91: indices.collect {|key| self[convert_key(key)]} 92: end
# File lib/mail/indifferent_hash.rb, line 131 131: def convert_key(key) 132: key.kind_of?(Symbol) ? key.to_s : key 133: end
# File lib/mail/indifferent_hash.rb, line 135 135: def convert_value(value) 136: if value.class == Hash 137: self.class.new_from_hash_copying_default(value) 138: elsif value.is_a?(Array) 139: value.dup.replace(value.map { |e| convert_value(e) }) 140: else 141: value 142: end 143: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.