Created
December 3, 2012 09:09
-
-
Save yhara/4193770 to your computer and use it in GitHub Desktop.
FizzBuzz using Enumerable#lazy.
This file contains hidden or 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
fizzer = [nil, nil, "Fizz"].cycle | |
buzzer = [nil, nil, nil, nil, "Buzz"].cycle | |
puts (1..Float::INFINITY).lazy.zip(fizzer, buzzer) | |
.map{|i, fizz, buzz| | |
fizz || buzz ? "#{fizz}#{buzz}" : i | |
} | |
.first(20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(update) that SEGV is fixed by nobu :) http://bugs.ruby-lang.org/issues/7507