Jese Leos

Bare Metal FizzBuzz

If I were deploying this somewhere, I would lean towards something that looks more like the readable_solution below.

But for the sake of the challenge:

def solution(number)
 "#{"Fizz" if (number % 3).zero?}#{"Buzz" if (number % 5).zero?}"
end

raise unless solution(3) == "Fizz"
raise unless solution(5) == "Buzz"
raise unless solution(15) == "FizzBuzz"

puts "It works!"

If this were a one-liner competition, I would like my chances. 😄

def readable_solution(number)
 modulo_3 = (number % 3).zero?
 modulo_5 = (number % 5).zero?

 if modulo_3 && modulo_5
   "FizzBuzz"
 elsif modulo_3
   "Fizz"
  elsif modulo_5
    "Buzz"
  end
end