Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created February 7, 2020 01:01
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 gr33n7007h/e698b9da402f69d1bd1c2c8be14c920c to your computer and use it in GitHub Desktop.
Save gr33n7007h/e698b9da402f69d1bd1c2c8be14c920c to your computer and use it in GitHub Desktop.
FizzBuzz using Ruby 2.7 pattern matching.
#!/usr/bin/env ruby
fizzbuzz = -> (n) {
case [n % 3, n % 5, n]
in 0, 0, _; "FizzBuzz"
in 0, _, _; "Fizz"
in _, 0, _; "Buzz"
else n
end
}
puts (1..100).map &fizzbuzz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment