From: "s.ross" Date: 2008-04-05T13:38:42+09:00 Subject: Re: The ||= assignment operator On Apr 4, 2008, at 8:53 PM, Avdi Grimm wrote: > On this topic, am I the only one who would really like to see a > dedicated "defaulting operator" in Ruby? Something that actually has > the semantics which a lot of people mistakenly assume for ||=, i.e. > "assign if and only if nil"? I think Perl6 uses the //= operator for > this. This is such a subtle gotcha. I've seen a lot of code that was > potentially buggy because it didn't account for the fact that the > 'false' value would be handled incorrectly. > > -- > Avdi This would be great, but you would need both a // and //= operator. Consider this: @my_web_page_title = @page_name || "d'oh! you forgot to name your page" You would want to rewrite this as: @my_web_page_title = @page_name // "d'oh! you forgot to name your page" It would seem that adding these operators has a low potential to introduce bugs into working code and, as you point out, there are subtleties WRT the ||= idiom. Moving it from idiom to first-class operator might clarify those subtleties.