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

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"

reject

hsh.reject {| key, value | block } â a_hashhsh.reject â an_enumerator Instance Public methods Same as Hash#delete_if, but works on (and returns) a copy of the hsh. Equivalent to hsh.dup.delete_if.

reject!

hsh.reject! {| key, value | block } â hsh or nilhsh.reject! â an_enumerator Instance Public methods Equivalent to Hash#delete_if, but returns nil if no changes were made.

replace

hsh.replace(other_hash) â hsh Instance Public methods Replaces the contents of hsh with the contents of other_hash. h = { "a" => 100, "b" => 200 } h.replace({ "c" => 300, "d" => 400 }) #=> {"c"=>300, "d"=>400}

select

hsh.select {|key, value| block} â a_hashhsh.select â an_enumerator Instance Public methods Returns a new hash consisting of entries for which the block returns true. If no block is given, an enumerator is returned instead. h = { "a" => 100, "b" => 200, "c" => 300 } h.select {|k,v| k > "a"} #=> {"b" => 200, "c" => 300} h.select {|k,v| v < 200} #=> {"a" => 100}

select!

hsh.select! {| key, value | block } â hsh or nilhsh.select! â an_enumerator Instance Public methods Equivalent to Hash#keep_if, but returns nil if no changes were made.

shift

hsh.shift â anArray or obj Instance Public methods 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. h = { 1 => "a", 2 => "b", 3 => "c" } h.shift #=> [1, "a"] h #=> {2=>"b", 3=>"c"}

size

hsh.size â 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

store

hsh.store(key, value) â value Instance Public methods Element Assignment Associates the value given by value with the key given by key. h = { "a" => 100, "b" => 200 } h["a"] = 9 h["c"] = 4 h #=> {"a"=>9, "b"=>200, "c"=>4} key should not have its value changed while it is in use as a key (an unfrozen String passed as a key will be duplicated and frozen). a = "a" b = "b".freeze h = { a => 100, b => 200 } h.key(100).equal? a #=> false h.key(200).equal?