Created
November 10, 2019 06:09
-
-
Save kmizu/4139b0cdac7066c1a06ada6dc79d87ee to your computer and use it in GitHub Desktop.
Use Ruby 2.7's pattern matching
This file contains hidden or 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 reverse(xs) | |
case xs | |
in [y, *ys] | |
reverse(ys) + [y] | |
in [] | |
[] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment