From: aalfred Date: 2007-04-24T19:40:06+09:00 Subject: Re: Strange syntax sugar On Apr 24, 5:37 am, Jeff wrote: > On Apr 23, 7:40 pm, aalfred wrote: > > > I've recently had to deal with lots of assignments, where most of them > > looked > > like those two lines: > > > foo = bar if !bar.nil? # (case 1) or > > foo = bar if foo.nil? && !bar.nil? # (case 2) > > > (I know it could be written using 'unless', but I strongly dislike > > 'unless') > > I think you won't need your new sugar if you just rewrite the > originals: > > foo = bar if bar # case 1 > foo ||= bar if bar # case 2 > > That's the simplest and cleanest, I think. There is a subtelty in the assignment that is hard to see at the first glance: you *never* assign nil to foo (but assign can false). So your rewrite is not equivalent.