you have defined a singleton method for the object NilClass
I know I defined a singleton method for object a, but I don't quite
understand why I am defining a singleton for NilClass, by doing
def NilClass.method_missing...
Can NilClass be an object name rather than the Class NilClass? If I am
defining a singleton method, then, does the OBJECT NilClass has to exist
before I define the singleton method?
thanks,
Shannon
···
On Sun, 6 Jun 2004 19:31:56 +0900 ts <decoux@moulon.inra.fr> wrote:
you have defined a singleton method for the object NilClass
I know I defined a singleton method for object a,
You have defined a singleton method for the object NilClass, actually.
But it sounds like you knew that.
but I don't quite
understand why I am defining a singleton for NilClass, by doing
def NilClass.method_missing...
Can NilClass be an object name rather than the Class NilClass? If I am
defining a singleton method, then, does the OBJECT NilClass has to exist
before I define the singleton method?
Yes it must exist (ruby creates it before running your program). No,
NilClass can't refer to anything else unless you assign something else
to it first (NilClass is a constant just like any other capitalized
identifier), which is almost certainly a silly thing to do.
If you really insist, though, you can reassign it thusly:
Object.const_set('NilClass', 100)
HTH
···
On Sun, 6 Jun 2004 19:31:56 +0900 > ts <decoux@moulon.inra.fr> wrote: