class method
Enumerator::Product.new
[unchecked out Elem] (*::_EachEntry[Elem]) -> ::Enumerator::Product[Elem]
Enumerator::Product.new(*enums) → enum
enumerator.c
View on GitHub ↗
static VALUE
enum_product_initialize(int argc, VALUE *argv, VALUE obj)
{
struct enum_product *ptr;
VALUE enums = Qnil, options = Qnil;
rb_scan_args(argc, argv, "*:", &enums, &options);
if (!NIL_P(options) && !RHASH_EMPTY_P(options)) {
rb_exc_raise(rb_keyword_error_new("unknown", rb_hash_keys(options)));
}
rb_check_frozen(obj);
TypedData_Get_Struct(obj, struct enum_product, &enum_product_data_type, ptr);
if (!ptr) rb_raise(rb_eArgError, "unallocated product");
RB_OBJ_WRITE(obj, &ptr->enums, rb_ary_freeze(enums));
return obj;
}
Generates a new enumerator object that generates a Cartesian product of given enumerable objects.
Example
e = Enumerator::Product.new(1..3, [4, 5]) e.to_a #=> [[1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]] e.size #=> 6