From: Stefano Crocco Date: 2007-09-28T16:21:49+09:00 Subject: Re: Making 'new' private in a C extension. Alle gioved� 27 settembre 2007, alterego@sdf.lonestar.org ha scritto: > Hello all, > > I'm writing a C extension, one of the classes I define can only be > instantiated via a defined 'get_instance' singleton method. This method > will only ever return one instance, that is, successive calls will always > return exactly the same ruby object. > > My problem is that someone could still call 'new' on the class. I'd like > to remove that possibility by making 'new' private. Unfortunately I can't > for the life of me work out how. > > Any help on this subject will be much appreciated. - Tom > > ============= > Go Burma! > ============= I think you need to use the C function rb_mod_private_method, defined in eval.c, which corresponds to the ruby method Module.private_class_method. But I think you can use the Singleton module provided with ruby: include it in your class and you get a class of which only an instance can exist. From the C code, you can use the function rb_mod_include. I hope this helps Stefano