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
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 or some_value = 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With