From: Robert Dober Date: 2006-07-27T17:34:33+09:00 Subject: Re: ||= in an expression ------=_Part_37858_19351747.1153989269707 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 7/27/06, rejoc wrote: > > Hello, > > I new to Ruby and curious about this language I do use (yeet). > > I was browsing through some libraries/modules and I found a line looking > like > > a[:i] ||=3D "a string" > > I could not find this syntax in any manual online (and googling "||=3D" i= s > not of much help :-( ) > > Can anyone tell me what it means > > TiA > > It is very useful as var ||=3D expr is a shortcut for var =3D expr unless defined? var and var which means if var is defined and evaluates to true it is left alone however if var is not defined or evaluates to false it is assigned expr. That means also that var ||=3D expr will overwrite nil *and* false values in var, a fact which seems to be overseen sometimes. Cheers Robert --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_37858_19351747.1153989269707--