T
trans. (T. Onoma)
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
}
Any ideas?
Thanks,
T.
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
}
Any ideas?
Thanks,
T.