From: Josh Cheek Date: 2010-06-15T09:35:24+09:00 Subject: Re: shorthand --0016e65a0934d0186b048906c735 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jun 14, 2010 at 5:41 PM, Rick DeNatale wrote: > This is close, except that it will blow up if x isn't already defined. > > another alternative might be > > (defined? x) ? (x || x = y) : y > > Which avoids the problem when x isn't defined, but isn't exactly what > the 'compiled' ruby code does, whether that 'code' is YARV 'byte > codes' or an AST in MRI pre 1.9 > > This implies to me that if x is not defined, then return y without modifying x. But this contradicts the reason I used ||= for (lazy assignment). $ irb ruby-1.9.1-p378 > defined? x => nil ruby-1.9.1-p378 > defined? x => nil ruby-1.9.1-p378 > x ||= 5 => 5 ruby-1.9.1-p378 > x => 5 --0016e65a0934d0186b048906c735--