Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Assigning the Rest of an Array to a Variable

When destructuring an array, you can unpack and assign the remaining part of it to a variable using the rest pattern

a = [1, 2, 3]
b, *rest = *a

b    # => 1
rest # => [2, 3]
a    # => [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment