Skip to content

Instantly share code, notes, and snippets.

@ir-norn
Last active September 27, 2015 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ir-norn/d6bc6afb7e9034c337c7 to your computer and use it in GitHub Desktop.
Save ir-norn/d6bc6afb7e9034c337c7 to your computer and use it in GitHub Desktop.
#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