From: John Lam Date: 2005-09-24T12:25:55+09:00 Subject: Implementing method_missing in C and blocks ------=_Part_3412_11152901.1127532352184 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I'm implementing a CLR <-> Ruby bridge using Managed C++ and the Whidbey (.NET 2.0 runtime). There are a lot of novel things in my bridge since I completely avoid usin= g Reflection to invoke methods. Instead, I use the lightweight code generatio= n (LCG) feature the Whidbey runtime to emit IL instructions on the fly that form "shims" that call the appropriate CLR object methods. I'd like to provide an elegant implementation of delegate shimming as well= . So, for example I'd like to do this: b =3D System::Windows::Forms::Button.new b.Click do |object, args| puts 'Clicked me' end I've encountered a blocking issue, and I'm wondering if folks on the list might have a workaround. I override Object.method_missing to perform symbol lookups. So far, I handle methods, properties, and field lookups without any problems in my shim (well avoiding boxing value types is a hard problem but that's a LONG story ...). I need to use method_missing to deal with Events as well. So far, I can detect that a block is present using the rb_block_given_p() method, which returns true as expected. Now my method_missing implementatio= n must be able to accept arbitrary numbers of parameters since parameters 1..= N are the actual parameters of the method that's missing. Now, you could provide a specific implementation of method_missing to "capture" the block in the parameter b, as in this example: def method_missing(name, &b) ... But I can't use this to capture the block in my method_missing implementation since I do not know how many parameters to expect. Is there some way for me to effectively get at the Proc object for the block from within a method_missing implementation that takes a variable number of arguments? Thanks -John ------=_Part_3412_11152901.1127532352184--