Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
What does "||=" mean?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tom Ha  
View profile  
 More options Apr 14 2008, 9:44 am
From: Tom Ha <rails-mailing-l...@andreas-s.net>
Date: Mon, 14 Apr 2008 15:44:55 +0200
Local: Mon, Apr 14 2008 9:44 am
Subject: What does "||=" mean?
Hi there !

I don't quite understand the following method (taken from RESTful
authentication) and can't google the problem since the Goog won't accept
the search term in question ("||=").

The method:

def current_user
    @current_user ||= (login_from_session || login_from_basic_auth ||
login_from_cookie || :false)
end

My question:

I know "||" means a boolean "or", but what does "||=" mean?
Can you translate the above method into a sentence?

Thank you very much for your help!
Tom
--
Posted via http://www.ruby-forum.com/.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
idleFingers  
View profile  
 More options Apr 14 2008, 9:51 am
From: idleFingers <m...@idlefingers.co.uk>
Date: Mon, 14 Apr 2008 06:51:45 -0700 (PDT)
Local: Mon, Apr 14 2008 9:51 am
Subject: Re: What does "||=" mean?
It's an idiom for @current_user = @current_user || ......

.. Helps to keep it DRY

On Apr 14, 2:44 pm, Tom Ha <rails-mailing-l...@andreas-s.net> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig Demyanovich  
View profile  
 More options Apr 14 2008, 9:55 am
From: "Craig Demyanovich" <cdemyanov...@gmail.com>
Date: Mon, 14 Apr 2008 09:55:04 -0400
Local: Mon, Apr 14 2008 9:55 am
Subject: Re: [Rails] What does "||=" mean?

@current_user ||= some_expression means use @current_user if it's non-nil or
true; otherwise, assign some_expression to @current_user and then use
@current_user.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Ha  
View profile  
 More options Apr 14 2008, 9:59 am
From: Tom Ha <rails-mailing-l...@andreas-s.net>
Date: Mon, 14 Apr 2008 15:59:09 +0200
Local: Mon, Apr 14 2008 9:59 am
Subject: Re: What does "||=" mean?
Thanks very much, idleFingers !

Btw, I like your nickname, seems like you're Mr DRY in person... :-)
Tom

--
Posted via http://www.ruby-forum.com/.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David A. Black  
View profile  
 More options Apr 14 2008, 9:59 am
From: "David A. Black" <dbl...@rubypal.com>
Date: Mon, 14 Apr 2008 09:59:29 -0400 (EDT)
Local: Mon, Apr 14 2008 9:59 am
Subject: Re: [Rails] Re: What does "||=" mean?
Hi --

On Mon, 14 Apr 2008, idleFingers wrote:

> It's an idiom for @current_user = @current_user || ......

The most accurate representation of how it expands is:

   @current_user || @current_user = x

(See ruby-talk for recent discussions of why this is, also:
http://dablog.rubypal.com/2008/3/25/a-short-circuit-edge-case)

David

--
Rails training from David A. Black and Ruby Power and Light:
   ADVANCING WITH RAILS   April 14-17          New York City
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
See http://www.rubypal.com for details and updates!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »