Method: Enumerator::Chain#initialize

Defined in:
enumerator.c

#Enumerator::Chain.new(*enums) ⇒ Enumerator

Generates a new enumerator object that iterates over the elements of given enumerable objects in sequence.

e = Enumerator::Chain.new(1..3, [4, 5])
e.to_a #=> [1, 2, 3, 4, 5]
e.size #=> 5


3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
# File 'enumerator.c', line 3173

static VALUE
enum_chain_initialize(VALUE obj, VALUE enums)
{
    struct enum_chain *ptr;

    rb_check_frozen(obj);
    TypedData_Get_Struct(obj, struct enum_chain, &enum_chain_data_type, ptr);

    if (!ptr) rb_raise(rb_eArgError, "unallocated chain");

    ptr->enums = rb_ary_freeze(enums);
    ptr->pos = -1;

    return obj;
}