From: rejoc Date: 2006-07-27T17:45:04+09:00 Subject: Re: ||= in an expression Farrel Lifson a �crit : > On 27/07/06, rejoc wrote: > > In Ruby > > nil || anObject > > will return anObject and > > anotherObject || anObject > > will return anotherObject (assuming it's value isn't nil) > > The expression > > a[:i] ||= "a string" > > is equivalent to > > a[:i] = a[:i] || "a string" > > (sort of like 'num+= 1' is the same as 'num = num + 1')If a[:i] is not > nil then it will remain unchanged. If it is nil then it will be set to > "a string". > > Farrel > Thanks a lot.