partition()
public
Returns two arrays, the first
containing the elements of enum for which the block evaluates to
true, the second containing the rest.
(1..6).partition {|i| (i&1).zero?}
Show source
/*
* call-seq:
* enum.partition {| obj | block } => [ true_array, false_array ]
*
* Returns two arrays, the first containing the elements of
* <i>enum</i> for which the block evaluates to true, the second
* containing the rest.
*
* (1..6).partition {|i| (i&1).zero?}
*
*/
static VALUE
enum_partition(obj)
VALUE obj;
{
VALUE ary[2];
RETURN_ENUMERATOR(obj, 0, 0);
ary[0] = rb_ary_new();
ary[1] = rb_ary_new();
rb_iterate(rb_each, obj, partition_i, (VALUE)ary);
return rb_assoc_new(ary[0], ary[1]);
}