Forum: Ruby Adding a method to String class as Ruby C extension

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Iñaki Baz C. (Guest)
on 2009-04-03 19:19
(Received via mailing list)
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.
Iñaki Baz C. (Guest)
on 2009-04-03 19:20
(Received via mailing list)
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.
This topic is locked and can not be replied to.