Ruby Hash Functions
EditRocket provides the following information on Hash functions in the Ruby source code builder.
clear - Removes all key-value pairs from hsh.
default= - Sets the default value, the value returned for a key that does not exist in the hash. It is not possible to set the a default to a Proc that will be executed on each key lookup.
default(key=nil) - Returns the default value, the value that would be returned by hsh[key] if key did not exist in hsh. See also Hash::new and Hash#default=.
default_proc - If Hash::new was invoked with a block, return that block, otherwise return nil.
delete(key) - Deletes and returns a key-value pair from hsh whose key is equal to key. If the key is not found, returns the default value. If the optional code block is given and the key is not found, pass in the key and return the result of block.
delete_if - Deletes every key-value pair from hsh for which block evaluates to true.
each - Calls block once for each key in hsh, passing the key and value to the block as a two-element array. Because of the assignment semantics of block parameters, these elements will be split out if the block has two formal parameters. Also see Hash.each_pair, which will be marginally more efficient for blocks with two parameters.
each_key - Calls block once for each key in hsh, passing the key as a parameter.
each_pair - Calls block once for each key in hsh, passing the key and value as parameters.
each_value - Calls block once for each key in hsh, passing the value as a parameter.
empty? - Returns true if hsh contains no key-value pairs.
fetch(key [, default] ) - "Returns a value from the hash for the given key. If the key can't be found, there are several options: With no other arguments, it will raise an IndexError exception; if default is given, then that will be returned; if the optional code block is specified, then that will be run and its result returned."
has_key?(key) - Returns true if the given key is present in hsh.
has_value?(value) - Returns true if the given value is present for some key in hsh.
include?(key) - Returns true if the given key is present in hsh.
index(value) - Returns the key for a given value. If not found, returns nil.
indexes(key, ...) - Deprecated in favor of Hash#select.
indices(key, ...) - Deprecated in favor of Hash#select.
initialize_copy hsh.replace(other_hash) - Replaces the contents of hsh with the contents of other_hash.
inspect - Return the contents of this hash as a string.
invert - Returns a new hash created by using hsh's values as keys, and the keys as values.
key?(key) - Returns true if the given key is present in hsh.
keys - Returns a new array populated with the keys from this hash. See also Hash#values.
length - Returns the number of key-value pairs in the hash.
member?(key) - Returns true if the given key is present in hsh.
merge!(other_hash) - Adds the contents of other_hash to hsh, overwriting entries with duplicate keys with those from other_hash.
merge(other_hash) - Returns a new hash containing the contents of other_hash and the contents of hsh, overwriting entries in hsh with duplicate keys with those from other_hash.
new(obj) - Returns a new, empty hash. If this hash is subsequently accessed by a key that doesn't correspond to a hash entry, the value returned depends on the style of new used to create the hash. In the first form, the access returns nil. If obj is specified, this single object will be used for all default values. If a block is specified, it will be called with the hash object and the key, and should return the default value. It is the block's responsibility to store the value in the hash if required.
pretty_print(q) -
pretty_print_cycle(q) -
rehash - Rebuilds the hash based on the current hash values for each key. If values of key objects have changed since they were inserted, this method will reindex hsh. If Hash#rehash is called while an iterator is traversing the hash, an IndexError will be raised in the iterator.
reject! - Equivalent to Hash#delete_if, but returns nil if no changes were made.
reject - Same as Hash#delete_if, but works on (and returns) a copy of the hsh. Equivalent to hsh.dup.delete_if.
replace(other_hash) - Replaces the contents of hsh with the contents of other_hash.
select - Returns a new array consisting of [key,value] pairs for which the block returns true. Also see Hash.values_at.
shift - Removes a key-value pair from hsh and returns it as the two-item array [ key, value ], or the hash's default value if the hash is empty.
size - Returns the number of key-value pairs in the hash.
sort - Converts hsh to a nested array of [ key, value ] arrays and sorts it, using Array#sort.
store(key, value) - Element Assignment---Associates the value given by value with the key given by key. key should not have its value changed while it is in use as a key (a String passed as a key will be duplicated and frozen).
to_a - Converts hsh to a nested array of [ key, value ] arrays.
to_hash - Returns self.
to_s - Converts hsh to a string by converting the hash to an array of [ key, value ] pairs and then converting that array to a string using Array#join with the default separator.
to_yaml( opts = {} ) -
update(other_hash) - Adds the contents of other_hash to hsh, overwriting entries with duplicate keys with those from other_hash.
value?(value) - Returns true if the given value is present for some key in hsh.
values - Returns a new array populated with the values from hsh. See also Hash#keys.
values_at(key, ...) - Return an array containing the values associated with the given keys. Also see Hash.select.
yaml_initialize( tag, val ) -