Skip to content

Instantly share code, notes, and snippets.

@bbonamin
Created May 13, 2022 19:43
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 bbonamin/344d7b2eff838b951d6bdd183abb8a05 to your computer and use it in GitHub Desktop.
Save bbonamin/344d7b2eff838b951d6bdd183abb8a05 to your computer and use it in GitHub Desktop.
Ruby Pattern Matching FizzBuzz
def fizz_buzz(number)
r = case {r3: number % 3, r5: number % 5, number:}
in { r3: 0, r5: 0} then "FizzBuzz"
in { r3: 0} then "Fizz"
in { r5: 0} then "Buzz"
else number
end
puts r
end
(10..17).each { |n| fizz_buzz n}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment