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.
我有一个关于符号含义的简单问题(我认为)。||= 在红宝石中是什么意思?我有一个代码片段说:
...||= [nil]
||= [nil]
是 "<<" 吗?普通方法?
x ||= y
意味着(几乎)相同的东西
x = x || y
(不过,它只评估x一次。)
x
它主要用于检查变量是否为假(nil或false),如果是,则将其设置为默认值。
nil
false