danielewski.dev

Get Head and Tail of an Array Using Splat

head, *tail = [1, 2, 3, 4]
head # => 1
tail # => [2, 3, 4]
head, *body, tail = [1, 2, 3, 4]
head # => 1
body # => [2, 3]
tail # => 4