Skip to content

Instantly share code, notes, and snippets.

@jacegu
Created December 29, 2010 21:26
Show Gist options
  • Save jacegu/759090 to your computer and use it in GitHub Desktop.
Save jacegu/759090 to your computer and use it in GitHub Desktop.
Yet another version of fizz buzz kata using open classes
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