4 ms·
Because Ruby doesn't have a to_boolean method. !! is used to convert "truthy" or "falsy" values [0] into true boolean true or false values. For example, d
by drusepth 9y ago
Because Ruby doesn't have a to_boolean method. !! is used to convert "truthy" or "falsy" values [0] into true boolean true or false values.
For example,
def user_signed_in?
!!current_user
end
This returns "true" or "false", instead of a (truthy) User object or a (falsy) nil.
[0] https://gist.github.com/jfarmer/2647362 https://gist.github.com/jfarmer/2647362