Created
December 29, 2010 21:26
-
-
Save jacegu/759090 to your computer and use it in GitHub Desktop.
Yet another version of fizz buzz kata using open classes
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
class Fixnum | |
def divisible_by_3? | |
self % 3 == 0 | |
end | |
def divisible_by_5? | |
self % 5 == 0 | |
end | |
end | |
class FizzBuzzGame | |
FIZZ = 'fizz' | |
BUZZ = 'buzz' | |
FIZZBUZZ = 'fizzbuzz' | |
def answer_for(number) | |
return FIZZBUZZ if number.divisible_by_3? and number.divisible_by_5? | |
return FIZZ if number.divisible_by_3? | |
return BUZZ if number.divisible_by_5? | |
number | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment