Last active
November 28, 2023 20:22
-
-
Save PragTob/f31482c9b0d35158c6933253adc524b4 to your computer and use it in GitHub Desktop.
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
module FizzBuzz | |
module_function | |
def fizz_buzz(number) | |
fizz = divisible_by?(number, 3) | |
buzz = divisible_by?(number, 5) | |
if fizz && buzz | |
"FizzBuzz" | |
elsif fizz | |
"Fizz" | |
elsif buzz | |
"Buzz" | |
else | |
number | |
end | |
end | |
def run | |
1.upto(100) do |number| | |
puts fizz_buzz(number) | |
end | |
end | |
def divisible_by?(number, divisor) | |
number % divisor == 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment