[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

To be not, or not to be not?

Ruby Freak

9/23/2008 4:03:00 AM

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)"




....
2 Answers

Yossef Mendelssohn

9/23/2008 4:57:00 AM

0

On Sep 22, 11:05=A0pm, Ruby Freak <twscann...@gmail.com> 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... (and
the spec at http://github.com/ymendel/truthy/tree/master/spec/trut...
b
if you're interested).

--
-yossef

TPReal

9/23/2008 8:05:00 AM

0

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-....