obj.nil? vs. obj == nil

前端 未结 7 802
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 22:08

Is it better to use obj.nil? or obj == nil and what are the benefits of both?

7条回答
  •  有刺的猬
    2020-11-29 22:27

    Some might suggest that using .nil? is slower than the simple comparison, which makes sense when you think about it.

    But if scale and speed are not your concern, then .nil? is perhaps more readable.

提交回复
热议问题