From: Bertram Scharpf Date: 2006-03-13T07:36:02+09:00 Subject: Re: Proposal: String#notempty? Hi Evan, Am Montag, 13. M�r 2006, 04:02:32 +0900 schrieb Evan Phoenix: > On 3/12/06, Bertram Scharpf wrote: > > I oftenly use `Numeric#nonzero?'. Actually, I miss its > > equivalent, a method maybe `String#notempty?', returning > > the string if it has a length and nil otherwise. > > How is this better than doing "not str.empty?". nickname.notempty? or forename vs. nickname.empty? ? forename : nickname This is especially convienient when nickname is non-trivial (e.g. a database query). Further, it's pretty short. Maybe not everyone's first choice but always mine. Another example: gets.chomp.notempty? || default A common case with `nonzero?' is: (a.major <=> b.major).nonzero? or a.minor <=> b.minor > Also, the method should really return false instead of nil. `nonzero?' does return `nil'. Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de