Maybe you want to undef the method before including a module.


On Fri, Dec 2, 2011 at 2:57 PM, Su Zhang <su.comp.lang.ruby / gmail.com> wrote:
> Hi list,
>
> Is there a built-in inverse operation of Module#include? Currently I have:
>
> class A
> end
>
> module B
>   > b
>  
> end
>
> module C
>   > c
>  
> end
>
> a = A.new
>
> class A
>   > end
> p a.foo # => :b
>
> class A
>   > end
> p a.foo # => :c
>
> class A
>   > end
> p a.foo # => :c
>
> So if module B has already been mixed in, it cannot be re-included again
> thus the foo method is not redefined to B#foo in the last include operation.
> Thus occurs to me when I use Inversion of Control (or dependency injection)
> to switch between various implementations of a certain interface. I was
> thinking that if I can somehow "exclude" the module and include it again
> then the problem would be solved, and hence the question.
>
> Or better yet, is there another way to achieve this kind of implementation
> switching?
>
> Regards,
>
> Su
>