[Nitro] Aspects

Trans transfire at gmail.com
Mon Aug 27 17:27:23 EDT 2007



On Aug 27, 12:39 pm, "George Moschovitis"
<george.moschovi... at gmail.com> wrote:
> >  So I'd like to focus on your lib. Do you have any time to
> > work on this today, George?
>
> I can find some time. You want to start from the code in glue/aspects.rb ??

I took a look at the code. Good thing is that it's very neatly written
and easy to understand. Koodos there. On the downside though this
implementation is a less efficient. For one thing, iteration over all
of ObjectSpace should never be needed. I don't mind keeping it in
there as a just in case fallback, but nothing more. But the main thing
is that, wrapping by means of instance_method(name).bind(self).call is
very slow. Also, as you surely know, it's too static and won't catch
some dynamic class changes.

I'd suggest instead of using the bind technique, that we just define
special name:original, name:before, name:after and name:around methods
(literally). Which look something like:

  alias name:original, name

  def name(args)
    name:before(args)
    name:original(args)
    name:after(args)
  end

  def name:before(args)
    advices_before[name].each do |advice|
      advice.call(args)
    end
  end

  def name:after(args)
    advices_after[name].each do |advice|
      advice.call(args)
    end
  end

The around advice is little more difficult (or we can just use a
before and an after together?).

Doing it that way, we can update advice, on a per method basis, and
not worry about re-wrapping methods, and whatnot.

Sound good? Shall I implement?

T.



More information about the Nitro-general mailing list