From: dblack@... Date: 2006-06-23T09:29:34+09:00 Subject: Re: How odd is Ruby code allowed to be? Hi -- On Fri, 23 Jun 2006, Roger Johansson wrote: > Ok, strange question maybe. > Anyway, Im new to Ruby and I decided to make a small Aop lib just to > learn all the nice things about ruby.. > > so in my lib I can define an aspect like this: > > > class MyAspect < Aspect > apply_to_types SomeClass, String, FooBar > > pointcut("some_method","some_prop=","some_prop","length").with( > LoggingInterceptor.new ) > end > > > Would this be considered valid in the Ruby world or is this just as > crazy as I think it look? > > The reason I decided to try to make the aspect as a class even though it > isnt intended to be instanciated is that since it inherits my Aspect > base, I get access to my dsl'ish methods in the scope of the class. > > I can then register this class in my Aop engine which extracts the info > out of the static structure. > > So is it valid or just madness? It looks to me a bit like you're using a class where you should use an instance. In other words, you're treating inheritance as instantiation. Why not: aspect = Aspect.new do |a| a.apply_to_types SomeClass, String, FooBar a.pointcut("some_method",...).with(LoggingInterceptor.new) a.register_with_aop_engine end Mind you, I know little enough about AOP that this may be completely on the wrong track. But it seems like what you want is an aspect, and you've got an Aspect class, so aspect = Aspect.new seems a good place to start. David -- David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) See what the readers are saying about "Ruby for Rails"! http://www.rubypowerandlight.com/quotes