From: Phrogz Date: 2010-03-30T21:40:12+09:00 Subject: Re: coercing nil/obj to false/true On Mar 29, 10:30 pm, Steve Howell wrote: > I can add something like this to my codebase, but I'm wondering if > something similar is already built in: > > def to_boolean x >     return !x.nil? > end If you really, really need exactly true or false based on the truthiness of the value, just do: !!x However, I would have all your methods return either a useful value or nil (or when appropriate, false), and just use that value in all your boolean expressions. For example, imagine an array-based stack. You could write: def top? !self.last.nil? end but I would instead recommend just writing: def top self.last end and let your users do: if recent = my_stack.top # do something with recent end