From: Robert Dober Date: 2007-09-07T03:54:01+09:00 Subject: Re: before, after and around Ruby 1.9 On 9/6/07, Trans wrote: > > > On Sep 5, 6:46 pm, Yukihiro Matsumoto wrote: > > Hi, > > > > In message "Re: before, after and around Ruby 1.9" > > on Thu, 6 Sep 2007 10:32:03 +0900, Joel VanderWerf writes: > > > > |What if you want to reopen _without_ the "around" semantics? > > > > I thought we need to remove the previous one first. > > > > |Could we have these two variations: > > | > > |class Foo < Foo # <-- This is a type error in 1.8 > > | def foo; super; end # AROUND > > |end > > | > > |class Foo > > | def foo; super; end # REDEFINE > > |end > > | > > |At least that is a conservative extension. > > > > Or maybe providing two supers, one for the current behavior, the other > > for the new. I don't whatever name is suitable for new super yet, > > however. > > How would you be sure (and why would you want to?) know when a > "previous" exists or not? It rarely make sense to avoid advice. > However, when absolutely needed one can fallback to directed calling > with things like: > > super_at(Object) Inheritance dependecies, oooouch, danger, hot do not touch! Mixin dependecies even worse imagine you want to refer to a mixed in method, maybe it was mixed in by an anonymous module, or the method was defined at instance level. After all it feels wrong to have around, before and after built into the language, this seems to be a job for the metaprogrammers not for Matz. I'd prefer having an easy way to do this with metaprogramming and then put the implementations into the library. if there were a method object tree rather than a stack and if each method object just had references to the defining Module/Singleton Module, would we not be *very* happy? module A def a; 222 end end module A def a; 132 end end class B include A def a; 110 end end class C < B def a; 60 end end class C include Module::new{ def a ; 52 end } end c = C.new ma = c.method :a ma = ma.unbind ma.bind(c).call => 52 ma.old.bind(c).call => 60 ma.super.bind(c).call => 110 and most importantly D= Class::new { define_method :a { -3 + ma.bind(self).call - 3 } } D.instance_method(:a).old == ma => true Cheers Robert > > or > > as(Object).foo > > T. > > > -- I'm an atheist and that's it. I believe there's nothing we can know except that we should be kind to each other and do what we can for other people. -- Katharine Hepburn