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> wrot=
e:
> Hi list,
>
> Is there a built-in inverse operation of Module#include? Currently I have=
:
>
> class A
> end
>
> module B
> =A0def foo
> =A0 =A0:b
> =A0end
> end
>
> module C
> =A0def foo
> =A0 =A0:c
> =A0end
> end
>
> a =3D A.new
>
> class A
> =A0include B
> end
> p a.foo # =3D> :b
>
> class A
> =A0include C
> end
> p a.foo # =3D> :c
>
> class A
> =A0include B
> end
> p a.foo # =3D> :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 operati=
on.
> Thus occurs to me when I use Inversion of Control (or dependency injectio=
n)
> 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 implementatio=
n
> switching?
>
> Regards,
>
> Su
>