Skip to content

Instantly share code, notes, and snippets.

@ngsw
Created September 9, 2012 09:39
Show Gist options
  • Select an option

  • Save ngsw/3683494 to your computer and use it in GitHub Desktop.

Select an option

Save ngsw/3683494 to your computer and use it in GitHub Desktop.
FizzBuzz Enumerator
#!/bin/env ruby
#-*- coding: utf-8 -*-
fizzbuzz = Enumerator.new do |y|
number = 1
loop do
fzbz = number % 15 == 0 ? "FizzBuzz" :
number % 5 == 0 ? "Buzz" :
number % 3 == 0 ? "Fizz" : number
number += 1
y.yield fzbz
end
end
puts fizzbuzz.first(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment