Created
December 29, 2010 20:53
-
-
Save jacegu/759063 to your computer and use it in GitHub Desktop.
Second solution for fizzbuzz kata with improved readability
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 FizzBuzzGame | |
FIZZ = 'fizz' | |
BUZZ = 'buzz' | |
FIZZBUZZ = 'fizzbuzz' | |
def answer_for(number) | |
return FIZZBUZZ if divisible_by_3?(number) and divisible_by_5?(number) | |
return FIZZ if divisible_by_3?(number) | |
return BUZZ if divisible_by_5?(number) | |
number | |
end | |
private | |
def divisible_by_3?(number) | |
number % 3 == 0 | |
end | |
def divisible_by_5?(number) | |
number % 5 == 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment