fetch

hsh.fetch(key [, default] ) â objhsh.fetch(key) {| key | block } â obj Instance Public methods 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 KeyError 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. h = { "a" => 100, "b" => 200 } h.fetch("a") #=&

eql?

hash.eql?(other) â true or false Instance Public methods Returns true if hash and other are both hashes with the same content.

empty?

hsh.empty? â true or false Instance Public methods Returns true if hsh contains no key-value pairs. {}.empty? #=> true

each_value

hsh.each_value {| value | block } â hshhsh.each_value â an_enumerator Instance Public methods Calls block once for each key in hsh, passing the value as a parameter. If no block is given, an enumerator is returned instead. h = { "a" => 100, "b" => 200 } h.each_value {|value| puts value } produces: 100 200

each_pair

hsh.each_pair {| key, value | block } â hshhsh.each_pair â an_enumerator Instance Public methods Calls block once for each key in hsh, passing the key-value pair as parameters. If no block is given, an enumerator is returned instead. h = { "a" => 100, "b" => 200 } h.each {|key, value| puts "#{key} is #{value}" } produces: a is 100 b is 200

each_key

hsh.each_key {| key | block } â hshhsh.each_key â an_enumerator Instance Public methods Calls block once for each key in hsh, passing the key as a parameter. If no block is given, an enumerator is returned instead. h = { "a" => 100, "b" => 200 } h.each_key {|key| puts key } produces: a b

each

hsh.each {| key, value | block } â hshhsh.each_pair {| key, value | block } â hshhsh.each â an_enumeratorhsh.each_pair â an_enumerator Instance Public methods Calls block once for each key in hsh, passing the key-value pair as parameters. If no block is given, an enumerator is returned instead. h = { "a" => 100, "b" => 200 } h.each {|key, value| puts "#{key} is #{value}" } produces: a is 100 b is 200

delete_if

hsh.delete_if {| key, value | block } â hshhsh.delete_if â an_enumerator Instance Public methods Deletes every key-value pair from hsh for which block evaluates to true. If no block is given, an enumerator is returned instead. h = { "a" => 100, "b" => 200, "c" => 300 } h.delete_if {|key, value| key >= "b" } #=> {"a"=>100}

delete

hsh.delete(key) â valuehsh.delete(key) {| key | block } â value Instance Public methods Deletes the key-value pair and returns the value 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. h = { "a" => 100, "b" => 200 } h.delete("a") #=> 100 h.delete("z")

default_proc=

hsh.default_proc = proc_obj or nil Instance Public methods Sets the default proc to be executed on each failed key lookup. h.default_proc = proc do |hash, key| hash[key] = key + key end h[2] #=> 4 h["cat"] #=> "catcat"