From: timsuth@... (Tim Sutherland) Date: 2004-11-13T07:53:26+09:00 Subject: Re: non-nil, etc. (was Re: true? & false?) In article <4193F1FB.1060509@hypermetrics.com>, Hal Fulton wrote: [...] >You put a smiley, but in all seriousness I've thought of this. >(Actually I'd use nonnil? or nnil?) > >In fact, when I'm writing code that no one else will see, > I sometime use methods like these: > > a1 = [] > a2 = [1,2,3] > s1 = "" > s2 = "a string" > h1 = {} > h2 = {1=>2, 2=>4} > > a1.null? # true > a1.nnull? # false > a2.null? # false > a2.nnull? # true > > s1.null? # true > h1.null? # true > > # And so on... > >See below, and let the flamefest begin. [...] nil.nil? # true nil.nnil? # false nil.nnnil? # true nil.nnnnil? # false class Object def method_missing(name, *args) if name.to_s =~ /^n*nil\?$/ name.to_s.size % 2 == 0 ? nil? : !nil? else super end end end