Skip to content

Instantly share code, notes, and snippets.

@PragTob
Last active November 28, 2023 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PragTob/f31482c9b0d35158c6933253adc524b4 to your computer and use it in GitHub Desktop.
Save PragTob/f31482c9b0d35158c6933253adc524b4 to your computer and use it in GitHub Desktop.
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