Created
July 5, 2021 14:52
-
-
Save abstractart/4e5a2539080a5d9a8f67bd419cc98dad to your computer and use it in GitHub Desktop.
A implementation of Fibonacci function using Ruby Fibers
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
fib = Fiber.new do | |
last = [0, 1] | |
while(true) | |
v = last.sum | |
last[0] = last[1] | |
last[1] = v | |
Fiber.yield v | |
end | |
end | |
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