rehash

hsh.rehash â hsh Instance Public methods 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 RuntimeError will be raised in the iterator. a = [ "a", "b" ] c = [ "c", "d" ] h = { a => 100, c => 300 } h[a] #=> 100 a[0] = "z" h[a] #=> nil h.rehash #=> {["z", "b"]=>100, ["c", "d"

rassoc

hash.rassoc(obj) â an_array or nil Instance Public methods Searches through the hash comparing obj with the value using ==. Returns the first key-value pair (two-element array) that matches. See also Array#rassoc. a = {1=> "one", 2 => "two", 3 => "three", "ii" => "two"} a.rassoc("two") #=> [2, "two"] a.rassoc("four") #=> nil

pretty_print_cycle

pretty_print_cycle(q) Instance Public methods

pretty_print

pretty_print(q) Instance Public methods

merge!

hsh.merge!(other_hash) â hshhsh.merge!(other_hash){|key, oldval, newval| block} â hsh Instance Public methods Adds the contents of other_hash to hsh. If no block is specified, entries with duplicate keys are overwritten with the values from other_hash, otherwise the value of each duplicate key is determined by calling the block with the key, its value in hsh and its value in other_hash. h1 = { "a" => 100, "b" => 200 } h2 = { "b" => 254,

merge

hsh.merge(other_hash) â new_hashhsh.merge(other_hash){|key, oldval, newval| block} â new_hash Instance Public methods Returns a new hash containing the contents of other_hash and the contents of hsh. If no block is specified, the value for entries with duplicate keys will be that of other_hash. Otherwise the value for each duplicate key is determined by calling the block with the key, its value in hsh and its value in other_hash. h1 = { "a" => 100,

member?

hsh.member?(key) â true or false Instance Public methods Returns true if the given key is present in hsh. h = { "a" => 100, "b" => 200 } h.has_key?("a") #=> true h.has_key?("z") #=> false

length

hsh.length â fixnum Instance Public methods Returns the number of key-value pairs in the hash. h = { "d" => 100, "a" => 200, "v" => 300, "e" => 400 } h.length #=> 4 h.delete("a") #=> 200 h.length #=> 3

keys

hsh.keys â array Instance Public methods Returns a new array populated with the keys from this hash. See also Hash#values. h = { "a" => 100, "b" => 200, "c" => 300, "d" => 400 } h.keys #=> ["a", "b", "c", "d"]

key?

hsh.key?(key) â true or false Instance Public methods Returns true if the given key is present in hsh. h = { "a" => 100, "b" => 200 } h.has_key?("a") #=> true h.has_key?("z") #=> false