Created
December 28, 2010 17:43
-
-
Save sirupsen/757461 to your computer and use it in GitHub Desktop.
Fizzbuzz in Ruby.
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
# not so insane | |
class Fixnum | |
def fizzbuzz | |
buffer = '' | |
buffer += 'Fizz' if self % 3 == 0 | |
buffer += 'Buzz' if self % 5 == 0 | |
buffer.empty? ? self : buffer | |
end | |
end | |
(1..100).each {|i| puts i.fizzbuzz } | |
# insane | |
1.upto 100 do |n| | |
puts [[:fizz][n%3], [:buzz][n%5]].join[/.+/m] || n | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment