[Nitro] Facets Aspects problem

Judson Lester nyarly at gmail.com
Thu Feb 1 20:07:27 EST 2007


On 2/1/07, transfire at gmail.com <transfire at gmail.com> wrote:
>
>
> 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)}
>           __unwrapped_#{m}(*a,&b)
>           #{gen_advice_code(m, target.advices, :post)}
>         end
>       end_eval
>     end
>
> Let me know.
>
> T.
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>


More information about the Nitro-general mailing list