Re: dynamic loading and unloading of module
Chris Roerig <[email protected]> Fri, 16 Aug 2019 06:10:12 -0500
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAAwyNq4UjRiJ6L-zdDeFK_UgQ6imUT=tj--xdpOYwxM1N-dJTQ@mail.gmail.com> |
I wouldn’t use a module here. Sounds like the factory pattern might be a better option. On Thu, Aug 15, 2019 at 5:10 PM Cary Swoveland <[email protected]> wrote: > Once a module is included, prepended or extended the action cannot be > reversed. Yes, you can remove its methods, but I don't know what you would > do about constants. > > Cary > > Sent from my Apple II+ > > > On Thu, Aug 15, 2019 at 1:50 AM ulli bei Unity <[email protected]> > wrote: > >> Hi, >> >> I want to load and remove dynamically Module in an application. Removing >> is possible, but >> >> I am not able to reload it. Is there any way to do it? >> >> Is it even recommendable to do something like this? >> >> Ulli >> >> >> >> >> module Mod >> def foo >> puts "fooing" >> end >> end >> >> module Modd >> def foo >> puts "fooing2" >> end >> end >> >> >> class C >> include Mod >> >> def self.remove_module(m) >> m.instance_methods.each{|m| undef_method(m)} >> end >> >> def self.addModul m >> include m >> end >> end >> >> c = C.new >> c.foo >> C.remove_module(Mod) >> >> C.addModul(Modd) >> c.foo >> >> >> >> >> >> >> Unsubscribe: <mailto:[email protected]?subject=unsubscribe> >> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> >> > > Unsubscribe: <mailto:[email protected]?subject=unsubscribe> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> > Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>