[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Adding a method to String class as Ruby C extension

Iñaki Baz Castillo

4/3/2009 3:18:00 PM

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 =3D 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.


--=20
I=C3=B1aki Baz Castillo
<ibc@aliax.net>

1 Answer

Iñaki Baz Castillo

4/3/2009 3:20:00 PM

0

2009/4/3 I=C3=B1aki Baz Castillo <ibc@aliax.net>:

> =C2=A0VALUE myClass =3D rb_define_class_under(myModule, "MyClass", rb_cOb=
ject);
>
> 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?i...
so rb_cString seems to be what I need.


--=20
I=C3=B1aki Baz Castillo
<ibc@aliax.net>