Created
May 14, 2014 01:31
-
-
Save jadon1979/a204854f61545851e1d9 to your computer and use it in GitHub Desktop.
Code Tests: FizzBuzz solution
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 FizzBuzz | |
| attr_reader :output | |
| def initialize(iterations = 100) | |
| @output = (1..iterations).map { |i| fizz_buzz_test(i) } | |
| end | |
| def fizz_buzz_test(iteration) | |
| case | |
| when iteration % 15 == 0 | |
| 'FizzBuzz' | |
| when iteration % 5 == 0 | |
| 'Buzz' | |
| when iteration % 3 == 0 | |
| "Fizz" | |
| else | |
| iteration | |
| end | |
| end | |
| def print | |
| @output.join(', ') | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment