我想使用多个赋值,但我不关心输入中的某些部分值。那么有没有办法将一些东西分配给void变量(bash中的/dev/null
)?类似nil = 'I wont be used'
。我有一个更具体的例子来说明我想要达到的目标。如何使用ruby的多重赋值将值赋给void变量?
我输入的是:
['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']
一种常见方法是只使用'_'作为占位符变量。 – halfelf