From: Robert Klemme Date: 2005-09-23T00:01:47+09:00 Subject: Re: Instantiating a subclass of NilClass. Trans wrote: > I've subclasses NilClass, but don't know how to instantiate it. Any > ideas? > > class NullClass < NilClass > def inspect ; 'null' ; end > def method_missing(*args) ; self ; end > end > > module Kernel > def null > NullClass.allocate #? > end > end > > T. Hm... I guess NilClass in Java lingo would be a final class, i.e., no inheritance allowed. Btw, why do you want to do that? I mean, you can create a class with nil-like behavior (apart from the boolean behavior I guess) without inheriting NilClass, can't you? require 'singleton' class NullClass include Singleton def inspect ; 'null' ; end def nil?() true end def method_missing(*args) ; self ; end end module Kernel def null NullClass.instance end end Kind regards robert