开发者

Unload a ruby class

开发者 https://www.devze.com 2023-01-11 00:12 出处:网络
I have the followin开发者_如何学编程g 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.

I have the followin开发者_如何学编程g 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?


Object.send(:remove_const, :Foo)

assuming your class is named Foo.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消