Skip to content

Instantly share code, notes, and snippets.

@ipoval
Last active September 28, 2015 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ipoval/1374820 to your computer and use it in GitHub Desktop.
Save ipoval/1374820 to your computer and use it in GitHub Desktop.
fibonacci_enumerator
fibonacci = Enumerator.new do |yielder|
n1, n2 = 0, 1
loop do
yielder.yield n1
n1, n2 = n2, n1 + n2
end
end
p fibonacci.first(20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment