Extra formatting and clarification of enumerator_feed [#4757]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ryan 2011-05-31 23:19:50 +00:00
parent f6809f61d6
commit f4273e88a8

View File

@ -714,26 +714,30 @@ enumerator_peek(VALUE obj)
* call-seq: * call-seq:
* e.feed obj -> nil * e.feed obj -> nil
* *
* Set the value to be returned by the next call to +yield+ by the enumerator. * Set the value for the next yield in the enumerator returns.
* If the value is not set, the +yield+ returns +nil+ and the value is cleared
* after it is used the first time.
* *
* +obj+:: the object to return from the next call to the Enumerator's +yield+ * If the value is not set, the yield returns nil.
* *
* === Example * This value is cleared after being used.
* *
* three_times = Enumerator.new do |yielder| * o = Object.new
* 3.times do |x| * def o.each
* result = yielder.yield(x) * x = yield # (2) blocks
* puts result * p x # (5) => "foo"
* end * x = yield # (6) blocks
* p x # (8) => nil
* x = yield # (9) blocks
* p x # not reached w/o another e.next
* end * end
* *
* three_times.next # => 0 * e = o.to_enum
* three_times.feed("foo") * e.next # (1)
* three_times.next # => 1, prints "foo" * e.feed "foo" # (3)
* three_times.next # => 2, prints nothing * e.next # (4)
* e.next # (7)
* # (10)
*/ */
static VALUE static VALUE
enumerator_feed(VALUE obj, VALUE v) enumerator_feed(VALUE obj, VALUE v)
{ {