← Back to Ruby Operators

Rest in Multiple Assignment

The asterisk symbol (*) is used as part of "Multiple Assignment" statements to capture the remaining elements in an array destructuring assignment.

> a, b, *rest = (1..10).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> a
=> 1
> b
=> 2
> rest
=> [3, 4, 5, 6, 7, 8, 9, 10]

References