From: Trans Date: 2006-10-15T00:40:17+09:00 Subject: Re: What's wrong with my metaprogramming? John Ky wrote: > >>>>> > def define_my_method(method_name) > define_method method_name do > yield > end > end Yea, funny thing about Ruby, closures go a long ways. Have a look at what self is in one fo your definitions: > class X > define_my_method :method1 do > puts "Method 1" > end > define_my_method :method2 do > puts "Method 2" p self > method1 > end > end > > X.new.method2 This is why define_method takes a block. So a fix would be: def define_my_method(method_name, &block) define_method method_name, &block end Unfortuantely that's not always the prefect solution since you might want to wrap extra code around the yield . In that case, you can use #instance_eval if you don't need to pass parameters. If you do need to pass parameters you'll have to use more complicated tricks until 1.9 introduces #instance_exec. On a related note, I still think it would be helpful if we could create clean-closure blocks. T.