Just wondering what !! is in Ruby.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not not.
It’s used to convert a value to a boolean:
It’s usually not necessary to use though since the only false values to Ruby are
nilandfalse, so it’s usually best to let that convention stand.Think of it as
One thing that is it used for legitimately is preventing a huge chunk of data from being returned. For example you probably don’t want to return 3MB of image data in your
has_image?method, or you may not want to return your entire user object in thelogged_in?method. Using!!converts these objects to a simpletrue/false.