On 5/5/10, James Masters <james.d.masters / gmail.com> wrote: > How can I do this with the Ruby C API? I looked at rb_str_replace in > string.c; however, that is not a public function in the C API. After Are you using ruby 1.8 or 1.9? 1.9 makes rb_str_replace non-static and declares it in intern.h. I don't see it in 1.8's intern.h, so its very likely static there. If you're on 1.9 I say just go ahead and call it. If on 1.8, you're looking at calling a static function from the outside which is difficult and icky at best. Official policy is that only funcs in ruby.h are considered part of the public api, and anything else shouldn't be used. Actually obeying this would mean that such useful and necessary utilities as rb_str_new and rb_ary_new couldn't be used by extensions, so it has to be taken with a gain of salt. I think you should be fairly safe with rb_str_replace. (Tho ruby maintainers are in effect reserving the right to change its calling conventions without warning or regret, it is unlikely they will do so.) > searching I found a few postings on this topic, I found that > rb_funcall could be initiated but this seems to add some overhead > which affects performance. Yeah, that's slow. And klutsy. Unfortunately, it is what you have to do to call a ruby method most of the time :(. If you're on 1.8, this is probably your best option. > I'm really just looking for a way to take a Ruby string VALUE and > replace the contents of that object with a C string in the most > efficient method possible. Can someone help me in doing this or at > least point me in the right direction? One other option is to fiddle directly with the fields of struct RString, but I don't recommend that unless you're really dedicated.