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.
我想知道 ruby 中 = 和 ||= 运算符之间的区别。在文档中,它说 = %= { /= -= += |= &= >>= <<= = &&= ||= * = are assignment operators 。
a ||= b简称a = a || b
a ||= b
a = a || b
在 rubynil 中,计算结果为 false。所以如果 a 是nilor false,a 将被赋予 b 的值
nil
false
如果是,之前的变量||=将接收运算符之后的值!= nil。
||=
!= nil