group_by()
public
Returns a hash, which keys are evaluated result from the block, and values
are arrays of elements in enum corresponding to the key.
(1..6).group_by {|i| i%3}
Show source
/*
* call-seq:
* enum.group_by {| obj | block } => a_hash
*
* Returns a hash, which keys are evaluated result from the
* block, and values are arrays of elements in <i>enum</i>
* corresponding to the key.
*
* (1..6).group_by {|i| i%3}
*
*/
static VALUE
enum_group_by(obj)
VALUE obj;
{
VALUE hash;
RETURN_ENUMERATOR(obj, 0, 0);
hash = rb_hash_new();
rb_block_call(obj, id_each, 0, 0, group_by_i, hash);
return hash;
}