instance method
Hash#each_pair
() { ([ K, V ] arg0) -> untyped } -> self
() -> ::Enumerator[[ K, V ], self]
each_pair {|key, value| ... } → self
each_pair → new_enumerator
hash.c
View on GitHub ↗
static VALUE
rb_hash_each_pair(VALUE hash)
{
RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
if (rb_block_pair_yield_optimizable())
rb_hash_foreach(hash, each_pair_i_fast, 0);
else
rb_hash_foreach(hash, each_pair_i, 0);
return hash;
}
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.