From: Morton Goldberg Date: 2007-09-06T13:12:53+09:00 Subject: Re: before, after and around Ruby 1.9 On Sep 5, 2007, at 7:32 PM, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: before, after and around Ruby 1.9" > on Thu, 6 Sep 2007 03:07:14 +0900, Trans > writes: > > |Any chance Ruby 1.9 will have before, after and around method > |composition support? > > No. Wait for 2.0 for built-in method combination. The vague plan is > making open-class to stack methods on the current ones, unless > explicitly removed, i.e. > > class Foo < Object > def foo > puts "Foo#foo (1)" > end > end > class Foo # re-open > def foo > super # calls the first foo > puts "Foo#foo (2)" > end > end > > will print > > Foo#foo (1) > Foo#foo (2) > > No alias required. > > This works as "around". And "before" and "after" can be rewritten > using "around". Note that this is not a fixed idea at all. Perhaps to avoid overloading 'super', you might use 'previous' or 'existing' since we would be calling a previously existing version of the method. class Foo < Object def foo puts "Foo#foo (1)" end end class Foo # re-open def foo previous puts "Foo#foo (2)" end end lass Foo < Object def foo puts "Foo#foo (1)" end end class Foo # re-open def foo existing puts "Foo#foo (2)" end end Just a suggestion. Regards, Morton