feed(p1) public

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)
Show source
Register or log in to add new notes.