From: William Djaja Tjokroaminata Date: 2002-08-14T21:52:34+09:00 Subject: Re: Is There an Inverse of 'rb_define_method'? nobu.nokada@softhome.net wrote: -------------------------------------- > It's done at compile time, but not run time. -------------------------------------- Agreed. ------------------------------------- > However, there are many other functions with non-negative > arity, "func(self, arg1)", "func(self, arg1, arg2)" and so on. > To invoke C function corresponding to ruby method, you must > distinguish them, and call_cfunc() does it. ------------------------------------- You mean, for user-defined functions in Ruby, the Ruby parser can actually generate non-negative arity C functions? I mean, for example, for def my_func (arg1, arg2, arg3 = val3) the parser can generate a corresponding C function like rb_define_method (classmod, "my_func", func_ptr, 3) ? In my mind, for any user-defined Ruby function, at least the parser will "equivalently" only generate rb_define_method (classmod, "my_func", func_ptr, -1); with rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3); (I said equivalently because it is not obvious how to get func_ptr from a user-defined Ruby function; probably through some intermediary proc object.) This is rather hard to believe; then probably reading parse.c will be interesting. ------------------------------------- > And a user can redefine methods, then the methods don't have > corresponding C functions. ------------------------------------- This may be a little bit tricky, because then it means I have to obtain the function pointer only after the parsing (of all user scripts) is completely done. Regards, Bill