# Unloading objects?

**URL:** <https://www.ruby-forum.com/t/unloading-objects/67347>\
**Category:** Ruby\
**Created:** [September 2, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/unloading-objects/67347 "2006-09-02T17:56:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [September 2, 2006, 5:56pm UTC](https://www.ruby-forum.com/t/unloading-objects/67347/1 "2006-09-02T17:56:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mgreenly](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85f322/32.png) [@mgreenly](https://www.ruby-forum.com/u/mgreenly)\
**Post date:** [September 5, 2006, 4:22am UTC](https://www.ruby-forum.com/t/unloading-objects/67347/2 "2006-09-05T04:22:56Z")

</div>

On 9/2/06, Michael G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

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
