From: Jim Freeze Date: 2003-05-09T23:28:38+09:00 Subject: Re: Can a global be a constant? On Friday, 9 May 2003 at 21:33:17 +0900, ts wrote: > >>>>> "J" == Jim Freeze writes: > > What do you do when someone write ? > > module A > def a > puts "a" > end > end > > a = [] > a.extend A > a.a > > a singleton class is an easy way to solve these problems, because when you > write 'a.extend(A)' ruby has made the include in the singleton class > associated with 'a' and you have something which is usefull, simple and > coherent (another argument against the multi-dispatch :-)))) > There you go twisting things up again. :) The pickaxe book doesn't provide figures for this behavior, but I assume that the a.extend creates a singleton class behind the scenes and points klass to the new singleton class. Then, the methods of A are not added to the singleton class, but a Proxy is created and the singletons super points to the proxy. The Proxy class then handles the method calls. Of course, all this is just a guess, since I have not seen it documented anywhere. Am I far off? -- Jim Freeze ---------- "What is wanted is not the will to believe, but the will to find out, which is the exact opposite." -- Bertrand Russell, "Skeptical_Essays", 1928