From: Robert Klemme Date: 2004-09-14T19:39:57+09:00 Subject: Re: Singleton method on object via define_method? "Mauricio Fern�ndez" schrieb im Newsbeitrag news:20040914095258.GA6742@student.ei.uni-stuttgart.de... > On Tue, Sep 14, 2004 at 05:34:54PM +0900, Robert Klemme wrote: > > .... but it might be a good reason to call it "virtual": it simply doesn't > > exist the whole time. :-) OTOH, you can't tell from the outside - it's > > there when you need it - lazyly initialized... ("lazy_class"? Oh no...) > > There's at least one case where you can know if the singleton class has > been created or not (singletons of singletons). How come? What's special about singletons here? > And you can always know > if you're using evil.rb, of course :-) How exactly would you want to do it? I don't see how eval helps here. The only way I can imagine is indirect: via instance_methods. But that test can only assure, that the singleton class is created, you can't be sure as long as the difference is empty: >> s="" => "" >> class << s ; def length() 1 end; end => nil >> s.methods - s.class.instance_methods => [] >> class << s ; def foo;"foo"; end; end => nil >> s.methods - s.class.instance_methods => ["foo"] Regards robert