A little help here. I'm trying to dynamically create a method that passes
through to another method but adds in a fixed argument. Unfortunately I can't
pass a block via a proc. How does one handle this? I ended up having to
create two methods for each wrapped method. Yuk. Here's the code snip:
# NOTE: wrap_advice is the method/proc used to wrap meth
# meth is defined in a subclass or singleton, c, to achieve wrapping
# define the interceptor
c.class_eval {
define_method("advice___#{meth}",wrap_advice)
}
c.class_eval %Q{
def #{meth}(*args,&blk)
target = proc{super} #proc{|*args,&blk| super(*args,&blk)}
advice___#{meth}(target,*args,&blk)
end
}
Notice also I can't pass the block via the proc'd super either. I want to just
do this:
# define the interceptor
c.class_eval {
define_method(meth) {|*args,&blk|
target = proc{|*args,&blk| super(*args,&blk)}
wrap_advice.call(target,*args,&blk)
end
}
A little help here. I'm trying to dynamically create a method that passes
through to another method but adds in a fixed argument. Unfortunately I can't
pass a block via a proc.
Why not? Or more lucidly (asfter this post a swear I'm going for
tea): what problems are you having? It seems like either of the methods
that Mauricio
> A little help here. I'm trying to dynamically create a method that passes
> through to another method but adds in a fixed argument. Unfortunately I
> can't pass a block via a proc.
Why not? Or more lucidly (asfter this post a swear I'm going for
tea): what problems are you having? It seems like either of the methods
that Mauricio
Ah, thank you. Thank you. Yes, this first example is essentially what I'm
doing. I see from it that block parameters in Procs are taken care of in
1.9+, I just need to update.
or I (about half way down, search for "$observers")
Ah, thank you. Thank you. Yes, this first example is essentially what I'm
doing. I see from it that block parameters in Procs are taken care of in
1.9+, I just need to update.
Actually, if you &-ize it on the way in you should be fine in 1.8
(at least, it works transparently for me).
*smile* I used to have that problem with my web browser cache
directory--it kept getting cluttered up with all these files with
cryptic names. It was annoying the tar out of me. Then I decided to
try a trick I'd developed with my mail spool directory: I stopped
looking in there.
That cleared the problem right up.
-- MarkusQ
···
On Fri, 2004-10-01 at 12:17, trans. (T. Onoma) wrote:
On Friday 01 October 2004 03:05 pm, Markus wrote:
> So, I'm curious right back: why the aversion to aliasing?
On Fri, 2004-10-01 at 12:17, trans. (T. Onoma) wrote:
> On Friday 01 October 2004 03:05 pm, Markus wrote:
> > So, I'm curious right back: why the aversion to aliasing?
>
> Simple: method namespace clutter.
*smile* I used to have that problem with my web browser cache
directory--it kept getting cluttered up with all these files with
cryptic names. It was annoying the tar out of me. Then I decided to
try a trick I'd developed with my mail spool directory: I stopped
looking in there.