Created
May 13, 2022 19:43
-
-
Save bbonamin/344d7b2eff838b951d6bdd183abb8a05 to your computer and use it in GitHub Desktop.
Ruby Pattern Matching FizzBuzz
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
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