Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我懂了:
x,(y,z)=1,*[2,3] x # => 1 y # => 2 z # => nil
我想知道为什么z有值nil。
z
nil
x, (y, z) = 1, *[2, 3]
*右侧的 splat是内联展开的,所以它相当于:
*
x, (y, z) = 1, 2, 3
左侧带括号的列表被视为嵌套赋值,因此相当于:
x = 1 y, z = 2
3被丢弃,而z被分配给nil.
3