Created
July 22, 2015 07:56
-
-
Save 284km/3a5f3ff68c6d540f13f4 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
class Fixnum | |
def fizzbuzz | |
return self if !fizz? && !buzz | |
[fizz, buzz].compact.join | |
end | |
private | |
def fizz | |
"fizz" if fizz? | |
end | |
def buzz | |
"buzz" if buzz? | |
end | |
def fizz? | |
self % 3 == 0 | |
end | |
def buzz? | |
self % 5 == 0 | |
end | |
end | |
class FizzBuzz | |
def self.call(*args) | |
new(*args).call | |
end | |
def initialize(max) | |
@max = max | |
end | |
def call | |
puts 1.upto(@max).map(&:fizzbuzz) | |
end | |
end | |
eval DATA.read | |
__END__ | |
FizzBuzz.call(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment