Re: dynamic loading and unloading of module

Cary Swoveland <[email protected]> Thu, 15 Aug 2019 15:10:07 -0700
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAJmrXRLRJ5FcFJ5JJSed845jni6LjE0mFzhd3c0=43BfqWbybA@mail.gmail.com>
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>