From: Jamey Cribbs Date: 2006-03-05T11:55:07+09:00 Subject: Re: Kirbybase Hacks NilClass Jamey Cribbs wrote: > Dave Burt wrote: > >> You can subclass NilClass, but it has no allocator, so you'd have to >> define your own, and such an object still wouldn't be considered >> false in conditionals. There is only one nil, and only one false. So >> there is no point in subclassing NilClass. >> >> >> > Yeah, I tried some of the same stuff Logan did in his email and > finally realized that NilClass won't let you subclass it. > > But, what if I did something like this: > > class KBNil > def method_missing(a,b) > nil > end > > def nil? > true > end > end > > Then, since, nil and false are the only things that don't evaluate to > true, if you do: > > k = KBNil.new > > puts 'True!' if k > 300 or 800 < 900 # True! > > puts 'False!' unless k > 300 or 800 < 900 # False! Oops! That should read: puts 'False!' unless k > 300 and 800 < 900 False! Jamey