/*
 *  call-seq:
 *     enum.cycle {|obj| block }
 *  
 *  Calls <i>block</i> for each element of <i>enum</i> repeatedly
 *  forever. Returns nil if and only if the collection is empty.
 *  Enumerable#cycle saves elements in an internal array so changes
 *  to <i>enum</i> after the first pass have no effect.
 *     
 *     a = ["a", "b", "c"]
 *     a.cycle {|x| puts x }  # print, a, b, c, a, b, c,.. forever.
 *     
 */

static VALUE
enum_cycle(VALUE obj)
{
    VALUE ary;
    long i, len;

    RETURN_ENUMERATOR(obj, 0, 0);
    ary = rb_ary_new();
    RBASIC(ary)->klass = 0;
    rb_block_call(obj, id_each, 0, 0, cycle_i, ary);
    len = RARRAY_LEN(ary);
    if (len == 0) return Qnil;
    for (;;) {
        for (i=0; i<len; i++) {
            rb_yield(RARRAY_PTR(ary)[i]);
        }
    }
    return Qnil;                /* not reached */
}