Skip to content

Instantly share code, notes, and snippets.

@chadbrewbaker
Created April 16, 2014 03:08
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 chadbrewbaker/10801878 to your computer and use it in GitHub Desktop.
Save chadbrewbaker/10801878 to your computer and use it in GitHub Desktop.
Wrapping an enumerator with a function to pass in parameters
def fibs(base)
fib = Enumerator.new do |y|
a = b = base
loop do
y.yield a
a, b = b, a + b
end
end
fib
end
p fibs(1).take(6)
p fibs(2).take(6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment