Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unload a ruby class

Tags:

ruby

I have the following in the file a.rb:

require foo

and i need to unload foo, to load the foo from b.rb, c.rb and other files.

How i can do?

like image 673
tapioco123 Avatar asked Aug 06 '10 14:08

tapioco123


2 Answers

Object.send(:remove_const, :Foo)

assuming your class is named Foo.

like image 154
lwe Avatar answered Sep 22 '22 03:09

lwe


I am not sure about the unloading part, but using load instead of require will always reload the file. However, when you use load you will need to include the .rb so in your case it would be load 'foo.rb' .

See http://www.fromjavatoruby.com/2008/10/require-vs-load.html

Kernel#load docs
Kernel#require docs

like image 25
gerryster Avatar answered Sep 24 '22 03:09

gerryster