Adding a method to String class as Ruby C extension


#1

Hi, I want to add a method to String class, and I want this method to
be defined in C.

In the C code, to add a method I must do:

rb_define_method(myClass, “hello”, hello, arg_count);

but I don’t know how to set myClass to point to String class.

To create a new class I should do:

VALUE myClass = rb_define_class_under(myModule, “MyClass”,
rb_cObject);

Since rb_cObject means Ruby Object class, could be rb_cString what I’m
looking for?

Thanks.


#2

2009/4/3 Iñaki Baz C. removed_email_address@domain.invalid:

 VALUE myClass = rb_define_class_under(myModule, “MyClass”, rb_cObject);

Since rb_cObject means Ruby Object class, could be rb_cString what I’m
looking for?

Auto reply:
I’ve found the following example:
http://bugs.gentoo.org/attachment.cgi?id=156407
so rb_cString seems to be what I need.