From: UpsNDowns Date: 2008-02-17T18:09:55+09:00 Subject: Re: object specific methods and id Gary Wright wrote: > On Feb 16, 2008, at 3:30 PM, UpsNDowns wrote: > >>Alas, my problem now is, that an assignment for my CS class >>requires me to prove that the obj is an instance of the singleton. >>(And no, it's no trick question, the teacher has even lectured >>about it and proposed a solution at the labs--- which btw I don't >>buy). > > > Well, prove the teacher wrong showing that their definition of > 'instance of' is ambiguous. You could take a test driven approach > and write some tests that describe the expected behavior of a class > and its instance. Then try the tests against different types of > objects: > 1) Looking at the ruby code (the C) it appears that the teacher may be right in a technical sense. Fx the 'rb_class_real' method of object.c 'peels' off any singletons before returning the class of an object. (However that is also odd as the singletons get special help from the VM that goes beyond their creation. In a clean solution, I *guess*, the singletons could be completely ordinary classes once they're made). 2) I suspect this is the real reason Mr. Black was so vague on the implementation of the singletons, in the slides I refered to earlier on. Perhaps singletons really are implemented as a subclass, put it's not the ruby way to think of it that way. Kind regards