Skip to content

Instantly share code, notes, and snippets.

@plexus
Created July 14, 2013 09:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save plexus/5993733 to your computer and use it in GitHub Desktop.
Save plexus/5993733 to your computer and use it in GitHub Desktop.
class FizzBuzz
def fizz
loop do
["", "", "Fizz"].each{|s| yield s}
end
end
def buzz
loop do
["", "", "", "", "Buzz"].each{|s| yield s}
end
end
def fizzbuzz
return to_enum(:fizzbuzz) unless block_given?
fizz = to_enum(:fizz)
buzz = to_enum(:buzz)
(1..Float::INFINITY).each do |i|
fizzbuzz = [fizz.next, buzz.next].join
yield fizzbuzz.empty? ? i : fizzbuzz
end
end
end
puts FizzBuzz.new.fizzbuzz.take(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment