[Nitro] Facets Aspects problem

transfire at gmail.com transfire at gmail.com
Thu Feb 1 18:11:42 EST 2007

On Feb 1, 5:49 pm, "nya... at gmail.com" <nya... at gmail.com> wrote:
> In trying to reduce the amount of eval'd code in Og I ran across the
> following fascinating snippet in facets/more/aspects.rb:
> target.instance_method(m).arity.times { |i| args << "a#{i}" }
> Which is fine, unless the method takes a variable number of arguments,
> in which case, the advised version of the method suddenly takes no
> arguments.

Good catch. That has to change.

> Can I suggest:
> arity = target.instance_method(m).arity
> if arity < 0
>   (-(arity + 1).times{ |i| args << "a#{i}" }
>   args << "*argv"
> else
>   arity.times { |i| args << "a#{i}" }
> end
> Working on a workaround...

Is this even eval'd too? What up with the "a#{i}"? Any wrapped method
can work with:

  (*a, &b)

No matter what the original args are. Hold on, let me look at the
code... Okay try this:

    for m in [methods].flatten
      target.module_eval <<-end_eval, __FILE__, __LINE__
        alias_method :__unwrapped_#{m}, :#{m}
        def #{m}(*a,&b)
          #{gen_advice_code(m, target.advices, :pre)}
          #{gen_advice_code(m, target.advices, :post)}

Let me know.


More information about the Nitro-general mailing list