Class: Enumerator::Generator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
enumerator.c

Instance Method Summary (collapse)

Methods included from Enumerable

#all?, #any?, #chunk, #collect, #collect_concat, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_entry, #each_slice, #each_with_index, #each_with_object, #entries, #find, #find_all, #find_index, #first, #flat_map, #grep, #group_by, #include?, #inject, #map, #max, #max_by, #member?, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reduce, #reject, #reverse_each, #select, #slice_before, #sort, #sort_by, #take, #take_while, #to_a, #zip

Constructor Details

- (Object) initialize

:nodoc:



# File 'enumerator.c'

/* :nodoc: */
static VALUE
generator_initialize(int argc, VALUE *argv, VALUE obj)
{
    VALUE proc;

    if (argc == 0) {
    rb_need_block();

    proc = rb_block_proc();
    } else {
    rb_scan_args(argc, argv, "1", &proc);

    if (!rb_obj_is_proc(proc))
        rb_raise(rb_eTypeError,
             "wrong argument type %s (expected Proc)",
             rb_obj_classname(proc));

    if (rb_block_given_p()) {
        rb_warn("given block not used");
    }
    }

    return generator_init(obj, proc);
}

Instance Method Details

- (Object) each

:nodoc:



# File 'enumerator.c'

/* :nodoc: */
static VALUE
generator_each(VALUE obj)
{
    struct generator *ptr = generator_ptr(obj);
    VALUE yielder;

    yielder = yielder_new();

    return rb_proc_call(ptr->proc, rb_ary_new3(1, yielder));
}

- (Object) initialize_copy

:nodoc:



# File 'enumerator.c'

/* :nodoc: */
static VALUE
generator_init_copy(VALUE obj, VALUE orig)
{
    struct generator *ptr0, *ptr1;

    ptr0 = generator_ptr(orig);

    TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr1);

    if (!ptr1) {
    rb_raise(rb_eArgError, "unallocated generator");
    }

    ptr1->proc = ptr0->proc;

    return obj;
}