Method: Hash#each_pair
- Defined in:
- hash.c
#each {|key, value| ... } ⇒ Hash #each_pair {|key, value| ... } ⇒ Hash #each ⇒ Object #each_pair ⇒ Object
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
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 |
# File 'hash.c', line 1762
static VALUE
rb_hash_each_pair(VALUE hash)
{
RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
if (rb_block_arity() > 1)
rb_hash_foreach(hash, each_pair_i_fast, 0);
else
rb_hash_foreach(hash, each_pair_i, 0);
return hash;
}
|