Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created November 10, 2019 06:09
Show Gist options
  • Save kmizu/4139b0cdac7066c1a06ada6dc79d87ee to your computer and use it in GitHub Desktop.
Save kmizu/4139b0cdac7066c1a06ada6dc79d87ee to your computer and use it in GitHub Desktop.
Use Ruby 2.7's pattern matching
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