instance method
Set#divide
() { (A, A) -> ::Hash::_Key } -> ::Set[self]
() { (A) -> ::Hash::_Key } -> ::Set[self]
divide { |o1, o2| ... } → set
divide { |o| ... } → set
divide → enumerator
set.c
View on GitHub ↗
static VALUE
set_i_divide(VALUE set)
{
RETURN_SIZED_ENUMERATOR(set, 0, 0, set_enum_size);
if (rb_block_arity() == 2) {
return set_divide_arity2(set);
}
VALUE values = rb_hash_values(set_i_classify(set));
set = set_alloc_with_size(rb_cSet, RARRAY_LEN(values));
set_merge_enum_into(set, values);
return set;
}
Divides the set into a set of subsets according to the commonality defined by the given block.
If the arity of the block is 2, elements o1 and o2 are in common if both block.call(o1, o2) and block.call(o2, o1) are true. Otherwise, elements o1 and o2 are in common if block.call(o1) == block.call(o2).
Example
numbers = Set[1, 3, 4, 6, 9, 10, 11] set = numbers.divide { |i,j| (i - j).abs == 1 } set #=> Set[Set[1], # Set[3, 4], # Set[6], # Set[9, 10, 11]]
Returns an enumerator if no block is given.