Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

boolean

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?

like image 285
Aaron Christiansen Avatar asked Jul 02 '16 18:07

Aaron Christiansen


1 Answers

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
like image 84
Silver Phoenix Avatar answered Sep 30 '22 14:09

Silver Phoenix