From: Chris McGrath Date: 2005-02-23T02:32:27+09:00 Subject: Re: Proposal for nil, 0, and "" in an if statement I'm pretty new to ruby, so may have this wrong, but if you're expecting nil or an empty string, can you not do bar.to_s.empty? and as nil.to_s == "" it'll return true for nil or an empty string. so: foo if bar.to_s.empty? foo(bar) unless bar.to_s.empty? Chris On Wed, 23 Feb 2005 02:22:45 +0900, Austin Ziegler wrote: > On Wed, 23 Feb 2005 00:32:02 +0900, Kaspar Schiess wrote: > > I can't see why this method should be added to all of Ruby.. it seems to > > apply to a special case you need to handle. You know, it is perfectly ok to > > change stdlib just for your project... this is what Ruby is about. > > > > I feel very at home with the distinction between empty and nil that is made > > currently. In the case of financial data that may have empty cells I would > > propose to add a small class layer between that has an empty? method.. thus > > solving the problem in an app specific way and not changing the language. > > This, or something like it, would be useful for the case where I have to do: > > foo if bar.nil? or bar.empty? > foo(bar) if bar and not bar.empty? > > It's not common, but it is common enough. I want to sometimes write it as: > > foo if bar.empty? > > ...because for the purposes of what I'm doing (I think that this is in > Text::Format), +nil+ is as good as empty. > > -austin > -- > Austin Ziegler * halostatue@gmail.com > * Alternate: austin@halostatue.ca > >