Skip to content

Instantly share code, notes, and snippets.

@foca
Created February 18, 2010 01:11
Show Gist options
  • Save foca/307218 to your computer and use it in GitHub Desktop.
Save foca/307218 to your computer and use it in GitHub Desktop.
>> fibs = Enumerator.new { |y| a, b = 0, 1; loop { y.yield a; b, a = a, a+b } }
>> fibs.first(10)
=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
>> fibs.take_while {|i| i < 60 }
=> [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment