From: Christian Rishoej Date: 2001-09-04T05:49:32+09:00 Subject: [ruby-talk:20812] Re: Proc internals In article <200109031946.f83Jk9352280@green.bikeshed.org>, "Brian F. Feldman" wrote: > They're not exactly interchangeable... There may be an answer depending > on what exactly it is that you want to do. The post from Henning von Rosen (`how update anonymous classes?'') gave me an excuse for investigating the internals of Ruby. I imagined a new instance method on Class: Class#add_method( methodName, &methodProc ) ....which would add the supplied Proc/Block and add it as a method to the particular instance of class. So far I have: ###################################### #include "ruby.h" VALUE rb_class_add_method(VALUE obj, VALUE methodName, VALUE methodProc) { int argc; ID id; Check_Type(methodName, T_STRING); if (!rb_obj_is_kind_of(methodProc, rb_cProc)) rb_raise(rb_eArgError, "Must pass a Proc"); argc = FIX2INT(rb_funcall(methodProc, rb_intern("arity"), 0)); id = rb_intern(STR2CSTR(methodName)); /* WHAT TO PUT HERE? */ return Qtrue; } void Init_add_method() { rb_define_method(rb_cClass, "add_method", rb_class_add_method, 2); } ###################################### First I thought of rb_define_method( class, name, C-function, arity ), but realizing that it expects a C funtion I gave up that idea. Then I had a look on rb_add_method which expects a NODE instead. If there is any way to get from a Proc to a NODE I figured I could use this. Any comments are greatly appreciated. Please excuse my lack of insight in the internals of Ruby. /Christian