[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

difference between rb_define_singleton_method and rb_define_method

sayoyo Sayoyo

1/16/2006 10:00:00 PM

Hi,

I wish to know what is the difference beteen rb_define_singleton_method
and rb_define_method???

I'm using rails-postgres and I need to access to a class defined in
postgres.so (I'm runing on Linux), the class name is PGconn. I find out
if the method which is defined with rb_define_singleton_method, the
ruby class PGconn will able to use but if the method is defined with
rb_define_method, the ruby class PGconn will not able to see it as a
method!!!! Ex:

rb_define_singleton_method(rb_cPGconn, "connect", pgconn_s_connect,
-1); # able to use
rb_define_method(rb_cPGconn, "close", pgconn_close, 0); # unable to see

Can anyone tell me why???

Thanks you very much

Sayoyo

2 Answers

gmurray

1/17/2006 1:12:00 AM

0

This is the first that I have seen that does not follow
(what I thought was a) convention. But I was unable to find
anything in writing that stated theconvention.
Nevertheless, you might think about this.

When declaring a class or module name, prefix the Constant
name with a 'c' for class, or 'm' for module. So the wrapper
would have the name:
cPGconn
Then this would be changed from:
rb_define_method(rb_cPGconn, "close", pgconn_close, 0);
to:
rb_define_method(cPGconn, "close", pgconn_close, 0);

Being unable to see may also be related to declaring the method
public, protected, or private, as these control the access.

Is this a wrapper for postgress? What is the package name. url
where this was found?

regards,
Gerald

sayoyo Sayoyo

1/17/2006 3:11:00 PM

0

Hi,

I take a look on the source file which create the library, I didn't
find any public, private, portected keyword, and I think the library is
written in C.

I wonder if rb_define_singleton_method is for the class method and
rb_define_method is for the object method am I correct?

and yes, this is a wrapper for postgresql database, I don't know the
package name, but I think the package is wrttien by matz in 1997

thanks you very much!!!

Sayoyo