Official expansion of ||= conditional assignment operator

前端 未结 2 1463
北荒
北荒 2021-01-18 07:37

I want to emphasize I am looking for the actual way the ||= operator is expanded by the Ruby 1.9.3 interpreter, not how it appears to be expan

2条回答
  •  一个人的身影
    2021-01-18 08:15

    x ||= y
    

    is a shorthand form for

    x || x = y
    

    If x is not nil and x is not false, the assignation will have place because of the short-circuit evaluation of the || operator.

提交回复
热议问题