Skip to content
instance method

Hash#each

() { ([ K, V ] arg0) -> untyped } -> self
() -> ::Enumerator[[ K, V ], self]
each

Alias of #each_pair

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

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

Output:

foo: 0
bar: 1
baz: 2

With no block given, returns a new Enumerator.

Related: see Methods for Iterating.

See also #each_pair #dig #each_key #delete_if also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0