From: Patrick Hurley Date: 2006-09-05T11:17:41+09:00 Subject: Re: unloading objects? On 9/2/06, Michael Gorsuch wrote: > I'm tinkering with various aspects of dynamic programming this morning, and > am curious to know if there is anyway to 'unload' a piece of ruby code? > > Example, I execute: > > load "room.rb" > > To load up by room class. > > What if I want to purge that definition? Is that possible? > > Yes and no, At a simple level, assuming there are no references to your class, removing the "const" on which it hangs will remove it from the system. It will take the semi-cryptic send invocation (or an instance_eval): Object.send :remove_const, :MyClassName or Object.instance_eval do remove_const :MyClassName end as remove_const is private -- also note that if you do have references to the class laying around the object is not really gone and you can still use it, but only via those references. You may also want to see _why's sandbox code for more powerful ways to "cleanup" pth