|
Parallel assignments have one more feature worth mentioning.
The left-hand side of an assignment may contain a parenthesized list of
terms. Ruby treats these terms as if they were a nested assignment
statement. It extracts out the corresponding rvalue, assigning it to
the parenthesized terms, before continuing with the higher-level
assignment.
b, (c, d), e = 1,2,3,4 |
� |
b == 1, |
c == 2, |
d == nil, |
e == 3 |
b, (c, d), e = [1,2,3,4] |
� |
b == 1, |
c == 2, |
d == nil, |
e == 3 |
b, (c, d), e = 1,[2,3],4 |
� |
b == 1, |
c == 2, |
d == 3, |
e == 4 |
b, (c, d), e = 1,[2,3,4],5 |
� |
b == 1, |
c == 2, |
d == 3, |
e == 5 |
b, (c,*d), e = 1,[2,3,4],5 |
� |
b == 1, |
c == 2, |
d == [3, 4], |
e == 5 |
|
|