Iterates through this Hash, calling the passed function for each key, passing to the function the current key as the first parameter. The method can take an optional second parameter as an Array object (arguments). The elements of this array will be passed to the function as additional parameters.

hash.each_key(func as Function, arguments? as Array) as Hash


  • func. A reference to a function. This function must have been defined with at least one parameter as the current key will be passed to it. This function may have additional parameters defined and these will be passed to it as the contents of the optional arguments array
  • arguments. Optional Array object. Each element of this array will be passed to func as additional parameters after the current key


  • This unaltered Hash


function put(key) {
    print("The key is " + key)
function putSuffix(key, suffix) {
    print("The key is " + key + suffix)
var h = {"a" => 100, "b" => 200}
# Prints:
# The key is a
# The key is b
h.each_key(putSuffix, [" silly!"])
# Prints:
# The key is a silly!
# The key is b silly!