Skip to content

Instantly share code, notes, and snippets.

@javascripter
Created March 23, 2010 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javascripter/341143 to your computer and use it in GitHub Desktop.
Save javascripter/341143 to your computer and use it in GitHub Desktop.
require 'generator'
fibs = Generator.new {|g|
a = 0
b = 1
loop {
g.yield a
a, b = b, a + b
}
}
fibs.each_with_index{|n,i|
break if i>100
puts n
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment