Skip to content
instance method

Hash#each_key

() { (K arg0) -> untyped } -> ::Hash[K, V]
() -> ::Enumerator[K, self]
each_key {|key| ... } → self
each_key → new_enumerator

With a block given, calls the block with each key; returns self:

Example
h = {foo: 0, bar: 1, baz: 2}
h.each_key {|key| puts key }  # => {foo: 0, bar: 1, baz: 2}

Output:

Example
foo
bar
baz

With no block given, returns a new Enumerator.

Related: see Methods for Iterating.

See also #each #each_pair #dig #each_value also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0