What does ||= (or-equals) mean in Ruby?

前端 未结 23 2882
情书的邮戳
情书的邮戳 2020-11-21 23:20

What does the following code mean in Ruby?

||=

Does it have any meaning or reason for the syntax?

23条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-21 23:31

    Please also remember that ||= isn't an atomic operation and so, it isn't thread safe. As rule of thumb, don't use it for class methods.

提交回复
热议问题