From: Rick DeNatale Date: 2009-05-06T10:31:53+09:00 Subject: Re: '=||' On Tue, May 5, 2009 at 8:45 PM, Eleanor McHugh wrote: > On 6 May 2009, at 00:09, 7stud -- wrote: >> >> Eleanor McHugh wrote: >>> >>> Are you referring to ||= ? If so it's one of the augmented assignment >>> operators so you won't find it documented separately as it's syntactic >>> sugar for: >>> >>> x = x || some_other_value >> >> Nope. ... >> The statement: >> >> x ||= val >> >> is actually equivalent to: >> >> x = val unless x > > > It seems you've misunderstood what happens under the hood when using > augmented assignment with tables as '||=' then becomes syntactic sugar for > 'x[] = x[] || some_other_value' and the assignment is performed via '[]=' > rather than '='. '[]=' will not create a key if it believes it already > exists and this is the cause of the behaviour you're seeing. No, if x is truthy then x ||= expression will NOT do any assignment. The real equivalent to x ||= y is x || x = y The assignment is short-circuited. For the proof see: http://talklikeaduck.denhaven2.com/2008/04/26/x-y-redux -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale