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

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

.. Helps to keep it DRY

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

Thanks very much, idleFingers !

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

Hi --