Re: dynamic loading and unloading of module
Xavier Noria <[email protected]> Tue, 20 Aug 2019 21:09:00 +0200
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAM=YcdiBTJELca2LUsEvkNQ-kCGt2ZZ_Tu0R=FN5sXWZ3A6mvw@mail.gmail.com> |
I believe the problem is that we do not know the original use case, right? You can redo trivially the ancestor chain of the parent class if you delete the constant and define the whole thing again. That is the approach taking to reload stuff in Rails. You can inject behavior to the singleton class of instances, so only the instance gets decorated, and the original class does not have the ancestor chain affected. Different instances may be decorated differently (this invalidates methods cache IIRC, but one thing is the technique needed to solve something, and a different thing is performance.) Active Support does some unloading by keeping a reference to original methods and restoring them, but it is very manual/ad-hoc. There are several techniques, it all depends on the details of what the OP wants to accomplish. How often do you want to "unload", why do you want to, etc. Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>