From: Ken Bloom Date: 2006-09-09T05:00:14+09:00 Subject: Re: better alias_method On Sat, 09 Sep 2006 02:54:35 +0900, Trans wrote: > ara.t.howard@noaa.gov wrote: >> heh. i think you may be hitting the same thing i was. here's some food for >> thought: >> >> >> this works: >> >> harp:~ > cat a.rb >> class C >> include Module.new{ def m() 'a' end } >> include Module.new{ def m() super + 'b' end } >> include Module.new{ def m() super + 'c' end } >> end >> >> p C.new.m >> >> >> harp:~ > ruby a.rb >> "abc" >> >> >> while this does not: >> >> harp:~ > cat a.rb >> class C >> def m() '' end >> >> include Module.new{ def m() super + 'a' end } >> include Module.new{ def m() super + 'b' end } >> include Module.new{ def m() super + 'c' end } >> end >> >> p C.new.m >> >> >> harp:~ > ruby a.rb >> "" >> >> even more distilled: >> >> harp:~ > cat a.rb >> class C >> def m() '' end >> >> include Module.new{ def m() 'a' end } >> end >> >> p C.new.m >> >> >> harp:~ > ruby a.rb >> "" >> >> >> i find that behviour quite suprising... in fact, it seems like a bug, but i'm >> probably wrong... thoughts? > > Not at all becasue inclusion adds to the inheritance chain, it doesn't > inject methods. You can of course define an #inject method if you like. > But it's still difficult to do the orginial intent of this thread b/c > of how #super works. > > Personally I think it would cool if you could redefine a method calling > on the previous definition just as one can redefine a variable calling > on it's previous definition. Eg. > > a = 1 > a = a + 1 > > def a ; 1 ; end > def a ; a + 1 ; end > > This would eliminate the need for #super except in cases of recursion, > in which case a special notation is also needed for the definition. Eg. > def_rec a, or something. But that's cool b/c it would be safer. > > In anycase, alternate solutions to the alias issue include > #wrap_method, see http://www.erikveen.dds.nl/monitorfunctions/index.html#implementation > #alias_chain, Matz' :before and :after system (semi-aop) and cuts (aop). Where is there information about these? --Ken -- Ken Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/