Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ||= mean? [duplicate]

Tags:

ruby

Possible Duplicate:
What does ||= (or equals) mean in Ruby?
What does ||= mean?

I have just started learning RubyMotion and in a lot of examples I see the ||= syntax. What does this mean?

Here is an example:

def window
  @window ||= begin
    w = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
    w.rootViewController = @navigationController
    w
end

It is difficult to search symbols, google ignored the symbols in my query.

like image 244
Josh Avatar asked Jul 20 '12 16:07

Josh


People also ask

What is the word duplicate means?

Definition of duplicate (Entry 1 of 3) 1 : consisting of or existing in two corresponding or identical parts or examples duplicate invoices. 2 : being the same as another duplicate copies. duplicate. verb.

What is the synonym of duplicate?

Some common synonyms of duplicate are copy, facsimile, replica, and reproduction. While all these words mean "a thing made to closely resemble another," duplicate implies a double or counterpart exactly corresponding to another thing.

What does Signed in duplicate mean?

Signing in counterpart means that duplicate contracts or deeds are printed so that there is a separate copy for signing by each party. The opposite situation is where one copy of the contract or deed is printed and signed by all parties to it.

What is an example of duplicate?

The definition of duplicate is having double. Two identical baseball cards in a stack are an example of a duplicate. To duplicate is defined as to make a copy. Making multiple copies of one form on a machine is an example of duplicate.


1 Answers

It is an assignment operator which means: or assign this value to a variable.

So if you did something like x ||= ythis meansx || x = y so if x is nil or false set x to be the value of y.

like image 62
ewein Avatar answered Oct 14 '22 02:10

ewein