From: dblack@... Date: 2006-12-13T01:57:24+09:00 Subject: Re: How do I catch a missing method on a passed block? Hi -- On Wed, 13 Dec 2006, J2M wrote: > > dblack@wobblini.net wrote: > >>>>> What made this sweet for me was turning the &block into a lambda let me >>>>> return the result from the instance_eval to bar where other solutions >>>>> kept them in scope of the &block. >>>> >>>> But the block *is* a lambda :-) That's what the &block argument does: >>>> it captures the code block in an object and assigns a variable to it. >>> >>> But without the lambda it is a raw proc that doesn't return the result >>> of the method - from what I understand from page 344 of Pickaxe. I >>> tried without and didn't get the result passed back from >>> method_missing, but I will now test that again :-) >> >> You may be right; I didn't demo it because I couldn't figure out >> exactly what code I needed to add :-) You may be hitting one of the >> Proc/proc/lambda/block difference things. > > You are right David, I chopped the lambda and it still works ;-/ > > I don't see how to get rid of the class variable as I am building a > hash from the repeated call to method_missing inside the block then > returning that through the instance_eval, if I don't use the class > variable, I will only get the result of the last call to > method_missing? I'd have to see the current version of the code to be sure, but define_method gives you a closure, so if you have a local variable outside it, that variable will be captured. Or maybe an instance variable. Can you post what you've currently got? David -- Q. What's a good holiday present for the serious Rails developer? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) aka The Ruby book for Rails developers! Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)