Skip to content

Instantly share code, notes, and snippets.

@jaydorsey
Last active July 5, 2018 18:47
Show Gist options
  • Save jaydorsey/cbbb9dcc13760b9d9f367899d9158e60 to your computer and use it in GitHub Desktop.
Save jaydorsey/cbbb9dcc13760b9d9f367899d9158e60 to your computer and use it in GitHub Desktop.
Fibonacci enumerator
fib = -> { Enumerator.new { |y| a = b = 1; loop { y << a; a, b = b, a + b } } }
puts fib.call.take(20)
x = fib.call
x.next => 1
x.next => 1
x.next => 2
...
x.next => 13
x.next => 21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment