On Mon, Jun 14, 2010 at 5:41 PM, Rick DeNatale <rick.denatale / gmail.com>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