From: Dominik Bathon Date: 2005-10-19T09:19:39+09:00 Subject: Re: The Ruby Way to build an object unless nil? On Tue, 18 Oct 2005 20:34:05 +0200, Peter Fitzgibbons wrote: > Hello all, > > I have this : > > def mymethod > a = someobjectreference('a') > if a.nil? > return nil > end > b = a.someattribute_might_be_nil > if b.nil? > return nil > end > c = b.someattribute_might_be_nil > if c.nil? > return nil > end > c.dosomething > end How about: def mymethod if a = someobjectreference('a') and b = a.someattribute_might_be_nil and c = b.someattribute_might_be_nil c.dosomething else nil end end It isn't exactly the same, because it would also return nil if a, b or c were false instead of nil. Dominik