To be not, or not to be not?

Discussion in 'Ruby' started by Ruby Freak, Sep 23, 2008.

  1. Ruby Freak

    Ruby Freak Guest

    That is not the question

    Code in question:

    module AuthenticatedSystem
    protected

    # Returns true or false if the user is logged in.
    # Preloads @current_user with the user model if they're logged in.
    def logged_in?
    !!current_user
    end
    ....

    Is !! as simple as it looks, or does it have meaning beyond a double
    negative? Google doesn't recognize !! in a search.

    I see it as "Not (current_user == Nil)"




    ....
     
    Ruby Freak, Sep 23, 2008
    #1
    1. Advertising

  2. On Sep 22, 11:05=A0pm, Ruby Freak <> wrote:
    > Is !! as simple as it looks, or does it have meaning beyond a double
    > negative? Google doesn't recognize !! in a search.


    It's as simple as it looks, which is up for debate. The point of the
    double negative is to concisely turn any into a boolean. !! will
    always result in either true or false.

    See http://github.com/ymendel/truthy/tree/master/lib/truthy.rb (and
    the spec at http://github.com/ymendel/truthy/tree/master/spec/truthy_spec.r=
    b
    if you're interested).

    --
    -yossef
     
    Yossef Mendelssohn, Sep 23, 2008
    #2
    1. Advertising

  3. Ruby Freak

    Thomas B. Guest

    Ruby Freak wrote:
    > I see it as "Not (current_user == Nil)"


    In fact, it is "Not (current_user == Nil Or current_user == False)"
    --
    Posted via http://www.ruby-forum.com/.
     
    Thomas B., Sep 23, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roxanne
    Replies:
    0
    Views:
    1,237
    Roxanne
    Jul 4, 2003
  2. Andy Elmhorst
    Replies:
    2
    Views:
    501
    Bassel Tabbara [MSFT]
    Jul 8, 2003
  3. Simon Chung-Jen Chuang
    Replies:
    1
    Views:
    3,975
    Ken Schaefer
    Aug 23, 2003
  4. Kristian Domke
    Replies:
    11
    Views:
    510
    George Sakkis
    Jan 23, 2008
  5. Stephanie Stowe
    Replies:
    2
    Views:
    220
    Peter X
    Apr 7, 2004
Loading...

Share This Page