>>>>> "N" == Norman Makoto Su <normsu / slab.tnr.sharp.co.jp> writes:

N> Just to make sure I understand things, if I want to simulate the following in C:

N> class Foo
N>   @@bar = 1
N> end

N> Then, I have to define foo in a "new" method, right?  Since bar is part of the
N> class definition and should be initialized before an instance is even created.

 No, why. In your ruby example you have not used ::new, why do you want use
 it in C ?


N> Also, regarding the CD Player example, I guess what I'm trying to ask is why
N> can't I do this?  (instead of using new)

N> static VALUE
N> cd_init(VALUE self, VALUE unit)
N> {
N>   CDJukebox *ptr = CDPlayerNew(NUM2INT(unit));
N>   rb_iv_set(self, "@unit", unit);
N>   VALUE tdata = Data_Wrap_Struct(self, 0, cd_free, ptr);
N>   return tdata;
N> }

N> I suspect that its because tdata will be a class and not an object?  But, the
N> thing is, the below does work:

 No, tdata is an object not a class. You can't write this because the
 return VALUE of #initialize is ignored by ruby and you'll lost the VALUE
 that you have created.

 With the new schema ::allocate allocate (:-)) the struct and #initialize
 initialize (:-)) the struct.

 With the old schema ::new create and initialize the struct (well sort of).


Guy Decoux