Skip to content

Instantly share code, notes, and snippets.

@tkfm-yamaguchi
Last active August 29, 2015 14:04
Show Gist options
  • Save tkfm-yamaguchi/fc47c16d24d5ef3cb1a4 to your computer and use it in GitHub Desktop.
Save tkfm-yamaguchi/fc47c16d24d5ef3cb1a4 to your computer and use it in GitHub Desktop.
fibfib(fibonacci and fiber)
# http://magazine.rubyist.net/?0034-FiberForBeginners
#
# fibonacci by Fiber
#
fib = Fiber.new do
a, b = 0, 1
loop do
a, b = b, a + b
Fiber.yield(a)
end
end
# fibonacci main
10.times do
puts fib.resume
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment