2006/2/16, Phil Tomson <ptkwt / aracnet.com>:
> In article <200602160202.15509.david / vallner.net>,
> David Vallner  <david / vallner.net> wrote:
> >D=C5=88a =C5=A0tvrtok 16 Febru=C3=A1r 2006 01:33 Phil Tomson nap=C3=ADsal:
> >> In article <200602152248.43632.david / vallner.net>,
> >>
> >> David Vallner  <david / vallner.net> wrote:
> >> >D=3DC5=3D88a Streda 15 Febru=3DC3=3DA1r 2006 08:48 Phil Tomson nap=3DC3=
> >=3DADsal:
> >> >> The only way to really get it to work would be to remove_method before
> >> >> doing the extend.  The problem with that is that remove_method doesn't
> >> >> wo=3D
> >> >
> >> >rk
> >> >
> >> >> in that context (removing singleton methods).
> >> >
> >> >Not even in the singleton class?
> >>
> >> I couldn't get it to work.  Maybe there's some way.
> >>
> >> However, I've come up with another way of doing what I was trying to do.
> >> What I needed was a Simulation functionality (where the code is run) and a
> >> Translation functionality (where the code translated to another language).
> >> Since the user doesn't need to switch from one to the other in the same r=
> >un
> >> it makes sense to inherit from a different class based on a commandline
> >> argument(or mixin a different module).
> >
> >I'll agree with Robert Klemme's previous post that you probably want to=20
> >delegate to a strategy in this case. Much less... well... weird. -And- you=
> >=20
> >can switch at your leisure too.
>
> Conditional inheritance considered weird?
>
> At one point or another much of what we now consider common practice was
> thought to be weird. ;-)

Well, certainly.  I can remember that we had a discussion about
implementing role pattern by changing inheritance. But since it
doesn't work as one would like I live with that and try different
approaches. IMHO it's also more fun to try to get the best out of what
one has than to try to change the rules of the game all the time. :-)
And Ruby is so extremely flexible that there's almost nothing that
can't be done.

Maybe we can make a variant of the extends approach work.  Here's how:
do not use extend directly but another method that simply stores the
module in a member variable. Then override method_missing to delegate
to methods of this module by rebinding them to self (is that possible?
need to try that).

Kind regards

robert

--
Have a look: http://www.flickr.com/photos/fussel-foto/