[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: unloading objects?

Patrick Hurley

9/5/2006 2:18:00 AM

On 9/2/06, Michael Gorsuch <michael.gorsuch@gmail.com> 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