在 2010-01-19二的 01:54 +0900,Colin Bartlett写道: > On Mon, Jan 18, 2010 at 3:44 AM, Ruby Newbee <rubynewbee / gmail.com> 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 > For those people who were coming from Perl, ||= is a pretty clear operator, :)