# Unloading (or unrequiring) a file

**URL:** <https://rubytalk.org/t/unloading-or-unrequiring-a-file/40009>\
**Category:** ruby-talk\
**Created:** [17 August 2007 22:58 UTC](https://rubytalk.org/t/unloading-or-unrequiring-a-file/40009 "2007-08-17T22:58:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ari\_Brown](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@Ari\_Brown](https://rubytalk.org/u/Ari_Brown)\
**Post date:** [17 August 2007 22:58 UTC](https://rubytalk.org/t/unloading-or-unrequiring-a-file/40009/1 "2007-08-17T22:58:34Z")

</div>

Hey all,

I'm trying to dynamically load parts of code to make things and methods available.

The catch is that I'd also like to make those things and methods UNavailable as well (or load something else in place of the original loaded item).

I know there's no Kernel#unload, so how can I achieve my goal?

Thanks,  
aRi  
-------------------------------------------|  
Nietzsche is my copilot

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [17 August 2007 23:14 UTC](https://rubytalk.org/t/unloading-or-unrequiring-a-file/40009/2 "2007-08-17T23:14:32Z")

</div>

> Hey all,
> 
> I'm trying to dynamically load parts of code to make things and  
> methods available.
> 
> The catch is that I'd also like to make those things and methods  
> UNavailable as well (or load something else in place of the original  
> loaded item).
> 
> I know there's no Kernel#unload, so how can I achieve my goal?

As far as methods go there's remove\_method and undef\_method. For  
constants theres remove\_const. An idea I've had was to fork, although  
that's a little heavy handed

eg:

... code ...  
pid = fork do  
&nbsp;&nbsp;&nbsp;require 'this\_will\_go\_away'  
&nbsp;&nbsp;&nbsp;but\_so\_will\_this\_var = ThisWillGoAway.new  
&nbsp;&nbsp;&nbsp;but\_so\_will\_this\_var.do\_something  
end

Process.wait pid

p but\_so\_will\_this\_var # NameError

> **···**
>
> On 8/17/07, Ari Brown \<ari@aribrown.com\> wrote:
> 
> > Thanks,  
> > aRi  
> > -------------------------------------------|  
> > Nietzsche is my copilot
