In ruby (and many other languages) there are many values that evaluate to true
in a boolean context, and a handful that will evaluate to false.
If you negate something, that forces a boolean context. Of course, it also negates it.
If you double-negate it, it forces the boolean context, but returns the proper boolean value.
For example:
"hello" -> this is a string; it is not in a boolean context
!"hello" -> this is a non-empty string that is forced into a boolean
context (true), and then negated (false)
!!"hello" -> this is a non-empty string that is forced into a boolean
context (true), and then negated (false), and then
negated again (true)
In your example, the signed_in?
method should return a boolean value (as indicated by convention by the ?
character). The internal logic it uses to decide this value is by checking to see if the current_user
variable is set. If it is set, it will evaluate to true
in a boolean context. If not, it will evaluate as false. The double negation forces the return value to be a boolean.