key

hsh.key(value) â key Instance Public methods Returns the key of an occurrence of a given value. If the value is not found, returns nil. h = { "a" => 100, "b" => 200, "c" => 300, "d" => 300 } h.key(200) #=> "b" h.key(300) #=> "c" h.key(999) #=> nil

keep_if

hsh.keep_if {| key, value | block } â hshhsh.keep_if â an_enumerator Instance Public methods Deletes every key-value pair from hsh for which block evaluates to false. If no block is given, an enumerator is returned instead.

invert

hsh.invert â new_hash Instance Public methods Returns a new hash created by using hsh's values as keys, and the keys as values. h = { "n" => 100, "m" => 100, "y" => 300, "d" => 200, "a" => 0 } h.invert #=> {0=>"a", 100=>"m", 200=>"d", 300=>"y"}

inspect

hsh.to_s â stringhsh.inspect â string Instance Public methods Return the contents of this hash as a string. h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 } h.to_s #=> "{\"c\"=>300, \"a\"=>100, \"d\"=>400}" to_s

initialize_copy

initialize_copy(p1) Instance Public methods

include?

hsh.include?(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

hash

hsh.hash â fixnum Instance Public methods Compute a hash-code for this hash. Two hashes with the same content will have the same hash code (and will compare using eql?).

has_value?

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

has_key?

hsh.has_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

flatten

hash.flatten â an_arrayhash.flatten(level) â an_array Instance Public methods Returns a new array that is a one-dimensional flattening of this hash. That is, for every key or value that is an array, extract its elements into the new array. Unlike Array#flatten, this method does not flatten recursively by default. The optional level argument determines the level of recursion to flatten. a = {1=> "one", 2 => [2,"two"], 3 => "three"} a.flatten # => [1, "one", 2, [2,