There is no core method that currently uses keyword arguments directly, i.e. klass.instance_method(:method).parameters
will never return :key
for builtin classes.
You probably have to define a method that accepts an argument, in this case a hash and parse it yourself. To do so, you can use rb_scan_args
with the :
argument to get a Hash
from the last argument (e.g. dir_initialize
) or code similar to the OPTHASH_GIVEN_P
macro (in array.c
). From the hash, you could use rb_get_kwargs
to get the values you want. I haven't looked into how to generate an error for unrecognized keyword arguments if you desire. I think most core methods don't do this check (at least yet).
You could have your method defined in Ruby using the keyword elements and call an internal C method from there. This would give you for free unknown keys being checked and a proper parameters
signature.
I hope to improve this situation with a revised api to define methods in Ruby 2.2 that would make it more natural to have keyword arguments in C functions, among other things (see this issue)