From: Markus Date: 2004-09-29T15:20:59+09:00 Subject: Re: DRY ruby idiom On Tue, 2004-09-28 at 21:30, Gavin Sinclair wrote: > Steve Tuckner wrote: > > a = "default" > > a = foo.value if foo.value > > > > I just wanted to see if there was a simple way to avoid the double > > foo.value that I was missing. Thanks for all your responses. > > Ah, well _that's_ easy: > > a = foo.value || "default" > > Gavin I was reading up this thread (I've been in meetings & working for the past 8 hrs or so, and thus neglecting my duties as a netizen) wondering if anyone had suggested this yet. Will I be the one to post it? Will I? *sigh* I will not that (in the original poster's terms), this is var = val || var which still repeats (but the computationally cheap var instead of the presumably costly val). There may be an idiom that avoids even that, but I'll be darned if I know what it is. -- MarkusQ P.S. In Icon (IIRC) you can write either var \= val or var /= val one of which effectively does var ||= val and the other var = val || var but the semantics of icon are sufficiently different from ruby to make this only an approximate analogy.