From: "T. Onoma" Date: 2003-11-23T17:30:33+09:00 Subject: Re: Method wrapper question (was "stereotyping (was ...)) After some exhaustive research and endless hours of thought I have put together a page at RiteSuggestions about Aspect Oriented Programming (AOP) for Ruby. (AOP is the overall term for programming with join-points which is what :pre, :post and :wrap represent.) Have a look at. http://www.rubygarden.org/ruby?AspectOrientedRuby As always, typo fixes and comments are welcome. -t0 On Sunday 23 November 2003 09:02 am, Ryan Pavlik wrote: > On Sat, 22 Nov 2003 23:33:57 +0900 > > "Christoph" wrote: > > ts wrote: > > ... > > > > > Yes, and this is why I prefer this scheme to > > > > > > class A > > > def a:pre > > > end > > > > > > def a:pre > > > end > > > > > > def a > > > end > > > end > > > > Agreed 100% - I see no reason for allowing several hooks in the same > > class. > > > > /Christoph > > Hmm, actually, there are a lot of good reasons for allowing multiple > hooks in the same class. This is, AFAIK, the point of having hooks at > all... so many people can hook into them. > > For instance, you may add a method:pre hook to check some parameter > values, make sure they're in range. You may include a package which > adds a :pre hook to add permissions. Etc. > > If you can only have one hook, what's the difference between doing > this: > > class Foo > def bar:pre > # pre stuff > end > > def bar > # body stuff > end > end > > > and doing this: > > class Foo > def bar > # pre stuff > # body stuff > end > end > > or even this: > > class Foo > def bar_pre > # pre stuff > end > > def bar > bar_pre > # body stuff > end > end > > To answer the question of order, it can either be configurable (I > think CLOS allows this) or simply "stack order" (latest defined :pre > goes first, latest defined :post goes last, etc.).