From: Chris Pine Date: 2002-12-12T03:51:19+09:00 Subject: Re: deleting a class Here's something weird: If instead of using the code: class Foo end ...I instead use... eval 'class Foo; end' ...then the rest of the code *does* delete the class! I just went through all of that in my mail "all the pretty evals..."; I was asking if these are the same. Obviously they aren't the same. So what's the difference? And what about the other evals: do they work like 'eval' does? What about 'require' and 'load'? (Those last two were rhetorical questions; I can figure it out on my own. I just want to know what the difference is and why it works this way.) Chris ----- Original Message ----- From: "Chris Pine" Newsgroups: comp.lang.ruby Sent: Wednesday, December 11, 2002 10:20 AM Subject: deleting a class Hello, I'm try to find a way to completely delete a class. (What I would eventually like is a way to load an entire GUI by default, but if the user requests a new one, I'd like to unload the old one and load up the new one.) So, in this code I create class Foo, but I can't figure out how to delete it. Am I doing the GC wrong, or is there some reference to Foo I haven't yet deleted? Or both? def getAllClasses classes = [] ObjectSpace.each_object (Class) do |klass| classes << klass.to_s end classes end def getAllConstants Module.constants end originalClasses = getAllClasses originalConstants = getAllConstants class Foo end Object.module_eval { remove_const 'Foo' } GC.start puts 'New classes: '+(getAllClasses - originalClasses ).join(', ') puts 'New constants: '+(getAllConstants - originalConstants).join(', ') Thanks for any help you can offer, Chris