On 24.04.2007 05:37, Jeff wrote: > On Apr 23, 7:40 pm, aalfred <alfred.anzlo... / gmail.com> 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. That's doubling the effort in the second case. Rather do foo &&= bar foo ||= bar As Jano pointed out, this reacts to false in the same way as to nil which might or might not be what you want. Kind regards robert