obj.nil? vs. obj == nil [英] obj.nil? vs. obj == nil
本文介绍了obj.nil? vs. obj == nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否最好使用 obj.nil?
或 obj == nil
?
推荐答案
最好使用obj.nil吗? or obj == nil
这完全一样。从外部(pfff) *
It is exactly the same. It has the exact same observable effects from the outside ( pfff ) *
可观察到的效果, / em>
and what are the benefits of both.
如果您喜欢微优化全部,对象将返回 false除了对象
nil
本身的 .nil?
消息 ==
消息将与另一个对象执行微小的微比较
,以确定它是否是同一个对象。
If you like micro optimizations all the objects will return false
to the .nil?
message except for the object nil
itself, while the object using the ==
message will perform a tiny micro comparison
with the other object to determine if it is the same object.
* 查看评论。
这篇关于obj.nil? vs. obj == nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文