From: Timothy Hunter Date: 2006-08-28T09:37:00+09:00 Subject: Re: Defining a method with default arguments in C Timothy Hunter wrote: > Brian Takita wrote: >> Hello, >> >> How can I define a default argument value such as the following in c? >> >> def foobar(arg=1) >> end >> >> Thanks, >> Brian Takita >> > Specify the number of arguments as -1 in rb_define_method: > > rb_define_method(myclass, "method_name", meth_fnc, -1); > > In your method use rb_scan_args to scan the argument list. If you > don't get enough arguments, use the default values instead. > My earlier post was incomplete. I should've explained that you should define your method like this: VALUE meth_fnc(int argc, VALUE *argv, VALUE self) { // stuff } argv is a C array of VALUEs, one for each argument passed to the method. argc is the number of VALUEs in argv. rb_scan_args takes argc and argv as arguments.