Subject: Re: The Ruby Way to build an object unless nil?
From: "Adam Sanderson" <netghost gmail.com>
Date: Thu, 20 Oct 2005 01:51:58 +0900
References: 161176
In-reply-to: 161176
Not quite a direct response, but the ||= idiom is also handy for these
things
ie:
irb(main):001:0> a = nil
irb(main):002:0> b = 4
irb(main):003:0> b ||= 7
=> 4
irb(main):004:0> b
=> 4
irb(main):005:0> a ||= b
=> 4
irb(main):006:0> a
=> 4
.adam