Created
June 23, 2013 01:27
-
-
Save depy/5843359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Iter | |
def initialize(arr) | |
@f = Fiber.new do | |
while item = arr.shift | |
Fiber.yield item | |
end | |
end | |
end | |
def next | |
@f.resume | |
end | |
end | |
i = Iter.new [1,2,3,2,1,0] | |
while item = i.next | |
puts item | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment