【发布时间】:2017-02-19 14:44:17
【问题描述】:
我想使用多重赋值,但我不关心我输入的部分值。那么有没有办法将某些东西分配给 void 变量(又名来自 bash 的 /dev/null)?类似nil = 'I wont be used'。我在下面有一个更具体的例子来说明我想要实现的目标。
我的输入是:
['no','foo','nop','not at all','bar']
我是这样分配的:
i,foo,dont,care,bar = ['no','foo','nop','not at all','bar']
#or with a splat :
dont,foo,*care,bar = ['no','foo','nop','not at all','bar']
我想做的是这样的:
nil,foo,*nil,bar = ['no','foo','nop','not at all','bar']
【问题讨论】:
-
一种常见的替代方法是使用
_作为占位符变量。
标签: ruby null variable-assignment assign assignment-operator