Last active
August 29, 2015 14:27
-
-
Save saxxi/2b3fa8c24e201f5c78ae to your computer and use it in GitHub Desktop.
Classic FizzBuzz in Ruby
This file contains 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 | |
def dump(total_numbers) | |
total_numbers.times do |i| | |
puts parse_string i + 1 | |
end | |
end | |
def parse_string(number) | |
is_divisible_by_3 = number % 3 == 0 | |
is_divisible_by_5 = number % 5 == 0 | |
if is_divisible_by_3 && is_divisible_by_5 | |
"FizzBuzz" | |
elsif is_divisible_by_3 | |
"Fizz" | |
elsif is_divisible_by_5 | |
"Buzz" | |
else | |
number | |
end | |
end | |
end | |
FizzBuzz.new.dump(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment