Method: Enumerator#feed
- Defined in:
- enumerator.c
#obj ⇒ nil
Set the value for the next yield in the enumerator returns.
If the value is not set, the yield returns nil.
This value is cleared after used.
o = Object.new
def o.each
# (2)
x = yield
p x #=> "foo"
# (5)
x = yield
p x #=> nil
# (7)
x = yield
# not reached
p x
end
e = o.to_enum
# (1)
e.next
# (3)
e.feed "foo"
# (4)
e.next
# (6)
e.next
# (8)
|
# File 'enumerator.c'
/*
* call-seq:
* e.feed obj -> nil
*
* Set the value for the next yield in the enumerator returns.
*
* If the value is not set, the yield returns nil.
*
* This value is cleared after used.
*
* o = Object.new
* def o.each
* # (2)
* x = yield
* p x #=> "foo"
* # (5)
* x = yield
* p x #=> nil
* # (7)
* x = yield
* # not reached
* p x
* end
* e = o.to_enum
* # (1)
* e.next
* # (3)
* e.feed "foo"
* # (4)
* e.next
* # (6)
* e.next
* # (8)
*
*/
static VALUE
enumerator_feed(VALUE obj, VALUE v)
{
struct enumerator *e = enumerator_ptr(obj);
if (e->feedvalue != Qundef) {
rb_raise(rb_eTypeError, "feed value already set");
}
e->feedvalue = v;
return Qnil;
}
|