From: Rob Biedenharn Date: 2008-06-12T06:23:49+09:00 Subject: Re: ||= On Jun 11, 2008, at 5:12 PM, Lyle Johnson wrote: > On Wed, Jun 11, 2008 at 3:59 PM, Justin To wrote: > >> what does ||= do? > > The expression: > > x ||= y > > is shorthand for: > > x = x || y > > where "||" is the OR-operator. If x evaluates as false or nil, the > value of y will be assigned to x; otherwise, x keeps its original > value. So, for example, > > x = nil > x ||= 42 # now x has value 42 > x ||= 23 # x stays at 42 > > Hope this helps, > > Lyle > Actually, it is like: x || x=y Refer to: http://dablog.rubypal.com/2008/3/25/a-short-circuit-edge-case -Rob