From: Jens Wille Date: 2008-09-19T05:44:48+09:00 Subject: Re: Singleton class's original class Thomas B. [2008-09-18 21:39]: > Now I'm wondering if it is possible to construct such an object > that belong to a foreign eigenclass and not be a class itself. In > other words, how to make my code fail even though a is not a > Class. Any ideas? not sure what you mean by that. but it fails for the singleton classes of objects like true, false, and nil (TrueClass, FalseClass, and NilClass resp.), which can safely be special-cased. here's the updated implementation: # strictly speaking it belongs under Class, # but i like to keep things together in this case class Object def singleton_object [true, false, nil].each { |obj| return obj if self.equal?(obj.singleton_class) } # raises TypeError if neither class nor module ObjectSpace.each_object(self) { |obj| return obj if self.equal?(obj.singleton_class) } # if we got here it can't be a singleton class # or its singleton object doesn't exist anymore raise TypeError rescue TypeError raise TypeError, 'not a singleton class' end end cheers jens