I am using some code that uses this syntax (restful authentication).
def logged_in?
!!current_user()
end
Tried googling for this but it just seems to ignore "!!", will accept an answer that can tell me how to find info about searching for strings such as !! in google.
Instance variables Examples: @foobar. The variable which name begins which the character ` @ ', is an instance variable of self . Instance variables are belong to the certain object. Non-initialized instance variables has value nil .
What you are seeing is the & operator applied to a :symbol . In a method argument list, the & operator takes its operand, converts it to a Proc object if it isn't already (by calling to_proc on it) and passes it to the method as if a block had been used.
It is just a naming convention To Ruby the exclamation mark, or bang (!), does not mean anything internally, it is just a naming convention that Ruby programmers use to denote that a method can be “dangerous”. According to this convention, the exclamation mark(!)
What's a Symbol in Ruby? A symbol is a unique instance of the Symbol class which is generally used for identifying a specific resource. A resource can be: a method.
It's double negation. The first !
converts it to false
if current_user
is not nil
or false
. After that it converts it to true
. So the result is always a boolean value and not the value of current_user
. The result is always true
if current_user
is not false
or nil
. Otherwise it's 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