From: Rob Biedenharn Date: 2008-06-12T06:21:28+09:00 Subject: Re: ||= On Jun 11, 2008, at 5:12 PM, Martin DeMello wrote: > On Wed, Jun 11, 2008 at 1:59 PM, Justin To wrote: >> what does ||= do? > > a ||= b is shorthand for a = a || b > > || is the "or" operator - a || b evaluates to a unless a is nil or > false, in which case it evaluates to b > > a ||= b is most commonly used to say "if a hasn't already been set > (and is therefore nil), set it to b, else leave it alone" > > martin Just to short-circuit the discussion: a ||= b is actually implemented as if: a || a=b Search for recent threads or find David A. Black's blog. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com