Trans
2/19/2007 2:58:00 AM
On Feb 18, 12:26 pm, "George Ogata" <george.og...@gmail.com> wrote:
> On 2/19/07, Pit Capitain <p...@capitain.de> wrote:
>
> > George, I'm not Tom, but I think that for redefining a method, instead of
>
> > class X
> > def a; "a2"; end
> > end
>
> > internally you would do something like
>
> > X.ancestors[ 1 ].module_eval {
> > def a; "a2"; end
> > }
>
> > Everything you would do with class X in normal Ruby you would do to the
> > anonymous module being the first in the ancestors chain.
>
> Hi Pit,
>
> Ah ok, I was overlooking the fact that *original* methods of X would
> live in an anonymous module as well.
>
> It's an interesting idea. It does still change the existing semantics
> a little, though. Currently, if you do:
>
> class C
> def f; 'C'; end
> end
>
> module M
> def f; 'M'; end
> end
>
> C.send(:include, M)
>
> ...C still comes first in the lookup path. You'd need to ensure that
> the anonymous modules (eigenmodules? ;-) come at the front of the
> ancestor chain if you wanted to preserve this behavior.
Actually, one of the benefits is that they would not come first,
becuase then you can override methods without resorting to alias and
what have you. However there's no reason we could not have the ability
to do both (which as you point out would benefit backward
compatability.) In fact as Pit points out we could have quite a bit of
flexibility accessing the module stack.
T.