From: Markus Date: 2004-10-02T02:42:02+09:00 Subject: Re: define_method, proc with block ? On Fri, 2004-10-01 at 09:08, trans. (T. Onoma) wrote: > 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 http://www.talkaboutprogramming.com/group/comp.lang.ruby/messages/107894.html or I (about half way down, search for "$observers") http://www.talkaboutprogramming.com/group/comp.lang.ruby/messages/107721.html, suggested on this thread should do the trick. -- MarkusQ > 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 > } > > Any ideas? > > Thanks, > T.