From: Logan Capaldo Date: 2007-09-03T00:00:46+09:00 Subject: Re: idiomatic way to assign if not nil? On 9/2/07, Phrogz wrote: > On Aug 31, 12:40 am, aalfred wrote: > > Recently I had a similar problem. After some refactoring of code > > I rewrote the code with two (non-existing, but very DRY operators) > > > > I had those two cases: > > > > foo = bar if !bar.nil? # (case 1) or > > foo = bar if foo.nil? && !bar.nil? # (case 2) > > > > and rewrote them into: > > > > foo ??= bar # case 1 > > foo !!= bar # case 2 > > How did you do that, given that those operators are (as you say) non- > existing, and the code in your resulting code produces a syntax error > (under 1.8.6, anyhow)? Did you modify the Ruby source? > I don't think he did any such thing. I think when he says he rewrote it, he means just that, he rewrote it, not that it actually worked or anything :) > >