零||假与假 ||在红宝石中为零 [英] nil || false and false || nil in ruby
本文介绍了零||假与假 ||在红宝石中为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
nil ||false
返回 false
和 false ||nil
返回 nil
.有人对此有解释吗?
nil || false
returns false
and false || nil
returns nil
. Does anyone have an explanation for this?
推荐答案
在 Ruby 中,一切都是表达式,表达式将返回在其中计算的最后一个值.
In Ruby, everything is an expression, and an expression will return the last value evaluated within it.
对于您的两个示例,||
表达式的左侧计算结果为假值,因此 Ruby 然后计算右侧并返回它.
For both of your examples, the left side of the ||
expression evaluates to a falsy value, so Ruby then evaluates the right side, and returns it.
这篇关于零||假与假 ||在红宝石中为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文