module FizzBuzz def to_fb s = '' s << (self % 3 == 0 ? 'Fizz' : '') s << (self % 5 == 0 ? 'Buzz' : '') s << self.to_s if s.empty? return s end end Integer.include(FizzBuzz) 1.upto(100) { |i| puts i.to_fb }
Edit to add: Actually, now that I think about it, using method_missing would have been even better!
But the edit window had passed by the time I changed it.