【发布时间】:2013-08-14 03:29:58
【问题描述】:
所以我刚刚(偶然)发现 Ruby 允许以下语法:
if foo and bar
或
if foo or bar.
这与(如果有的话?)有何不同
if foo && bar
if foo || bar
运营商是否不同?怎么样?
【问题讨论】:
所以我刚刚(偶然)发现 Ruby 允许以下语法:
if foo and bar
或
if foo or bar.
这与(如果有的话?)有何不同
if foo && bar
if foo || bar
运营商是否不同?怎么样?
【问题讨论】:
运营商是否不同?
是的,它们按照运算符的优先级。
怎么做?
有关详细信息,请参阅Difference between “and” and && in Ruby? 和 Difference between “or” and || in Ruby?
【讨论】:
and 和 or 是短路的,它们只是优先级较低