Destructuring and Splat
Assign several values at once, use * to collect the rest and ** for keywords.
Example
a, b = 1, 2
a, b = b, a
first, *rest = [1, 2, 3]
puts a, b, first, rest.inspect
x, (y, z) = 1, [2, 3]
puts y + zResult
2 1 1 [2, 3] 5
Exercise
Collect the rest.
a, r = [1, 2, 3]
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.