Last active
September 27, 2015 10:28
-
-
Save ir-norn/d6bc6afb7e9034c337c7 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
#require "Fiber" | |
class Enum_Generator | |
def initialize re , method | |
@f = Fiber.new do | |
re.__send__(method) do | n | | |
Fiber.yield n | |
end | |
end | |
end | |
def next | |
@f.resume | |
end | |
end | |
f = Enum_Generator.new [1,2,3], :cycle | |
6.times do p f.next end | |
toggle = Enum_Generator.new [true,false], :cycle | |
4.times do p toggle.next end | |
a = [true,false].cycle | |
4.times do p a.next end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment