From: Colin Bartlett Date: 2010-01-19T01:54:57+09:00 Subject: Re: what does this mean? On Mon, Jan 18, 2010 at 3:44 AM, Ruby Newbee wrote: > For this statement: > @speaks_english ||= @name.size > 6 > does it mean something like below? > if @name.size > 6 >    @speaks_english ||= @name.size > end As an addition to the other replies to your question, there is a useful post on this by Rick DeNatale, see below. Rick DeNatale also notes that x &&= y behaves similarly - it means: x && (x = y) I've emphasized the last sentence below because although I know the real meaning of ||= the point that it preserves the short-circuit nature hadn't occurred to me, and I think it's a useful help to remembering exactly what ||= does. http://talklikeaduck.denhaven2.com/2008/04/26/x-y-redux A while back there was quite a thread on the Ruby-lang mailing list about the real semantics of the expression. a[x] ||= some_value In many books and articles on Ruby the form: a = b Where is an operator like + is described as syntactic sugar for: a = a b While this is true in most cases, it isn't true if the operator is ||. ... Matz explains that the real expansion of x ||= y is: x || (x = y) ... Since || is a ‘short-circuit’ boolean operator, the left hand operand expression is only evaluated if the right hand operand expression evaluates to a logically false value, i.e. either nil or false. The way that Matz included ||= as an assignment operator makes perfect sense to me. *** The ||= assignment operator reserves the short-circuit nature of ||. ***