[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

C extensions using Singleton

Brian Palmer

1/20/2005 5:57:00 AM

Another C extension question for the experts: in a C ruby class, I'm
trying to use the Singleton standard library. It doesn't work, though
no errors are thrown.

ruby_rpg_class = rb_define_class("RPGEngine", rb_cObject);
rb_require("singleton");
rb_include_module(ruby_rpg_class, rb_const_get(rb_cObject,
rb_intern("Singleton")));

With this C code above, I can still call RPGEngine.new and get a new
instance of the class. RPGEngine.instance throws a NoMethodError.

Is the code above correct?

Thanks again,
-- Brian


4 Answers

ts

1/20/2005 10:17:00 AM

0

>>>>> "B" == Brian Palmer <brian@pocketmartiansoftware.com> writes:

B> ruby_rpg_class = rb_define_class("RPGEngine", rb_cObject);
B> rb_require("singleton");
B> rb_include_module(ruby_rpg_class, rb_const_get(rb_cObject,
B> rb_intern("Singleton")));

Add this

rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")),
rb_intern("included"), 1, ruby_rpg_class);


Guy Decoux




Brian Palmer

1/20/2005 4:41:00 PM

0

So just for clarity's sake: using rb_include_module skips the
"included" callback that usually happens when a module is included?

-- Brian


ts wrote:

>>>>>>"B" == Brian Palmer <brian@pocketmartiansoftware.com> writes:
>>>>>>
>>>>>>
>
>B> ruby_rpg_class = rb_define_class("RPGEngine", rb_cObject);
>B> rb_require("singleton");
>B> rb_include_module(ruby_rpg_class, rb_const_get(rb_cObject,
>B> rb_intern("Singleton")));
>
> Add this
>
> rb_funcall(rb_const_get(rb_cObject, rb_intern("Singleton")),
> rb_intern("included"), 1, ruby_rpg_class);
>
>
>Guy Decoux
>
>
>
>
>
>
>
>


ts

1/20/2005 4:50:00 PM

0

>>>>> "B" == Brian Palmer <brian@pocketmartiansoftware.com> writes:

B> So just for clarity's sake: using rb_include_module skips the
B> "included" callback that usually happens when a module is included?

No, not really

Module#include call #append_features and #included

rb_include_module() is the default function for Module#append_features


Guy Decoux


Brian Palmer

1/20/2005 7:25:00 PM

0

Got it. Thanks.

-- Brian


ts wrote:

>>>>>>"B" == Brian Palmer <brian@pocketmartiansoftware.com> writes:
>>>>>>
>>>>>>
>
>B> So just for clarity's sake: using rb_include_module skips the
>B> "included" callback that usually happens when a module is included?
>
> No, not really
>
> Module#include call #append_features and #included
>
> rb_include_module() is the default function for Module#append_features
>
>
>Guy Decoux
>
>
>
>
>
>