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

前端 未结 23 2932
情书的邮戳
情书的邮戳 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:45

    In short, a||=b means: If a is undefined, nil or false, assign b to a. Otherwise, keep a intact.

提交回复
热议问题