Unloading (or unrequiring) a file

A

Ari Brown

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
 
L

Logan Capaldo

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
require 'this_will_go_away'
but_so_will_this_var = ThisWillGoAway.new
but_so_will_this_var.do_something
end

Process.wait pid

p but_so_will_this_var # NameError
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top