Skip to content

Instantly share code, notes, and snippets.

@inopinatus
Last active June 28, 2019 00:26
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 inopinatus/dd09e71d402e8997b104faaead2c9235 to your computer and use it in GitHub Desktop.
Save inopinatus/dd09e71d402e8997b104faaead2c9235 to your computer and use it in GitHub Desktop.
ruby's little-known array parameter destructuring.
def list((head, *tail))
case tail.length
when 0
head&.fetch(:name).to_s
when 1
"#{list [head]} & #{list tail}"
else
"#{list [head]}, #{list tail}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment