[Nitro] Aspects

Trans transfire at gmail.com
Fri Aug 24 11:29:21 EDT 2007


I having a look at the aspects.rb code today. I understand there are
some issues with the code. I'd like to review it's functionality and
the issues involved with it.

Concerning basic design, the objective is of course to create pre,
post and around advice for methods. Now that's easy enough if methods
already exist, basically:

  alias _methodname, methodname

  def methodname

The difficulty comes when the methods do not already exist. For
instance, if we want to encapsulate a set of advice for reuse --which
technically is what an aspect is. It is further complicated when we
consider that methods can be dynamically added to a class/module after
an aspect is applied. So those are the basic issues that make general
implementation quite difficult.

I've been thinking of implementing this on top of cut.rb. Cuts already
basically handles this stuff, so it should be easy to build aspects.rb
with it.  However I'm not confident in the overall robustness of
cut.rb. Among other things it overrides Module#included and
Class#method_added, so I expect corner cases to arise where these
methods have been overridden elsewhere. I'm sure it could be improved,
but it's not easy --it's complex meta-programming. So I've been
thinking about how to build a better implementation of cut.rb using
delegation instead of dynamic methods. That implementation would
easily be more robust, but in this case, I'm not sure about
performance characteristics since it would be heavily reliant on
method_missing. (Basically imagine every method call being routed via

OTOH. maybe a whole different approach is in order.



More information about the Nitro-general mailing list