Class: Enumerator::Generator
- Includes:
- Enumerable
- Defined in:
- enumerator.c
Instance Method Summary collapse
-
#each(*args) ⇒ Object
:nodoc:.
-
#initialize(*args) ⇒ Object
constructor
:nodoc:.
-
#initialize_copy(orig) ⇒ Object
:nodoc:.
Methods included from Enumerable
#all?, #any?, #chain, #chunk, #chunk_while, #collect, #collect_concat, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_entry, #each_slice, #each_with_index, #each_with_object, #entries, #filter, #filter_map, #find, #find_all, #find_index, #first, #flat_map, #grep, #grep_v, #group_by, #include?, #inject, #lazy, #map, #max, #max_by, #member?, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reduce, #reject, #reverse_each, #select, #slice_after, #slice_before, #slice_when, #sort, #sort_by, #sum, #take, #take_while, #tally, #to_a, #to_h, #uniq, #zip
Constructor Details
#initialize(*args) ⇒ Object
:nodoc:
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 |
# File 'enumerator.c', line 1474
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 %"PRIsVALUE" (expected Proc)",
rb_obj_class(proc));
if (rb_block_given_p()) {
rb_warn("given block not used");
}
}
return generator_init(obj, proc);
}
|
Instance Method Details
#each(*args) ⇒ Object
:nodoc:
1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
# File 'enumerator.c', line 1522
static VALUE
generator_each(int argc, VALUE *argv, VALUE obj)
{
struct generator *ptr = generator_ptr(obj);
VALUE args = rb_ary_new2(argc + 1);
rb_ary_push(args, yielder_new());
if (argc > 0) {
rb_ary_cat(args, argv, argc);
}
return rb_proc_call_kw(ptr->proc, args, RB_PASS_CALLED_KEYWORDS);
}
|
#initialize_copy(orig) ⇒ Object
:nodoc:
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 |
# File 'enumerator.c', line 1501
static VALUE
generator_init_copy(VALUE obj, VALUE orig)
{
struct generator *ptr0, *ptr1;
if (!OBJ_INIT_COPY(obj, orig)) return obj;
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;
}
|