From: Joel VanderWerf Date: 2007-05-20T05:36:18+09:00 Subject: Re: Block Trouble (Binding Issue?) Pieter V. wrote: > I'm presently trying to work on a little metaprogramming project, but > am finding my efforts a little frustrated by ... well, I'm not rightly > sure what by. It seems to be a scoping issue, from what I can tell. Yup, it sure is. define_method(name, &block) changes the scope of block to the instance, but the yield still references a block in class Foo scope. A fix might be to replace yield with instance_eval(&b), as below, but that will preclude passing arguments to the block, in case you ever need to do that. Google for instance_exec for a discussion, hacks for the present, and hope for the future (1.9 has it)... > def self.special_meth(name, &b) > meth(name) do > # do something special > yield # <= This is the problematic call instance_eval(&b) > end > end > end -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407