-
-
Save 404pnf/2d4d1a72e095a193e688 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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