有TRUE`和TRUE;`之间有区别吗? [英] Is there a difference between `TRUE` and `true`?

查看:220
本文介绍了有TRUE`和TRUE;`之间有区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TrueClass FalseClass 的两个实例和 NilClass 以不同的名称:一个是小写字母,一个大写字母。一个实例出现,以评估其他:

There are two instances of TrueClass, FalseClass and NilClass with different names: one in lowercase and one in uppercase. One instance appears to evaluate to the other:

true # => true
TRUE # => true
true == TRUE # => true

有没有这两个常数之间的差异,如果是这样,有什么区别?如果它们是相同的,这些常量应该我在code使用?我应该写 SOME_VALUE = TRUE SOME_VALUE = TRUE

推荐答案

所不同的是,虽然真正是在Ruby中, TRUE关键字是一个常数:

The difference is that while true is a keyword in Ruby, TRUE is a constant:

true = 1
# => SyntaxError: Can't assign to true

TRUE = false
# => warning: already initialized constant TRUE
# => false

TRUE == true
# => false

这篇关于有TRUE`和TRUE;`之间有区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆