difference between rb_define_singleton_method and rb_define_method

S

sayoyo

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
 
G

Gerald Murray

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
 
S

sayoyo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top