OrangeFlash81 OrangeFlash81 - 1 year ago 60
Ruby Question

Is there a difference between `TRUE` and `true`?

There are two instances of

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

Is there a difference between these two constants, and if so, what are the differences? If they are the same, which of these constants should I use in my code? Should I write
some_value = true
some_value = TRUE

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download