Difference between “and” and && in Ruby?

前端 未结 7 1201
别跟我提以往
别跟我提以往 2020-11-22 09:28

What is the difference between the && and and operators in Ruby?

7条回答
  •  有刺的猬
    2020-11-22 09:36

    and is the same as && but with lower precedence. They both use short-circuit evaluation.

    WARNING: and even has lower precedence than = so you'll usually want to avoid and. An example when and should be used can be found in the Rails Guide under "Avoiding Double Render Errors".

提交回复
热议问题