Here is my understanding of the practical purpose of splat. This is for Ruby 2.2 MRI / KRI / YARV.
Ruby splat destroys an object in an array at the time of assignment.
All these examples give the same result when a false:
a = *(1..3) a = * (1..3) a =* (1..3) a = *1..3 a = * 1..3 a = * a || (1..3) a = * [1, 2, 3] => [1, 2, 3]
Split performs destructuring during installation, as if you wrote this:
a = [1, 2, 3]
(Note: calling splat calls #to_a . This means that there are no changes when marking up the array. It also means that you can define your own types of destructuring for any of your class if you want.)
But these statements are not fulfilled:
*(1..3) * 1..3 * [1,2,3] false || *(1..3) x = x ? x : *(1..3) => SyntaxError
These statements fail because there is no assignment that occurs exactly when the symbol occurs.
Your question in this case:
b ||= *(1..3)
Ruby extends it to:
b = b || *(1..3)
This instruction fails because there is no assignment that occurs exactly when the character occurs.
If you need to solve this in your own code, you can use temp var, for example:
b ||= (x=*(1..3))
Worth mentioning: here is a completely different use of splat when it is on the left side of the expression. This mark is a low-priority greedy compilation during a parallel assignment.
Examples:
*a, b = [1, 2, 3]
So this is a parsing:
*a = (1..3)
It sets a for all results on the right side, i.e. range.
In the rare case when a sign can be understood as a destructor or collector, then the destructor has a predisposition.
This line:
x = * y = (1..3)
Evaluates the following:
x = *(y = (1..3))
Not this:
x = (*y = (1..3))