From: Norman Makoto Su Date: 2002-04-24T10:15:31+09:00 Subject: Re: building extensions-- new vs initialize Hi, thanks for the reply. > In general, redefinition of "new" will be deprecated in 1.8. OK, I believe this will make things clearer. > No, once defined a class, you can define class variables > whenever. Typically in the Init function, "new" is called for > each object, however class variables are singleton. Just to make sure I understand things, if I want to simulate the following in C: class Foo @@bar = 1 end Then, I have to define foo in a "new" method, right? Since bar is part of the class definition and should be initialized before an instance is even created. Also, regarding the CD Player example, I guess what I'm trying to ask is why can't I do this? (instead of using new) static VALUE cd_init(VALUE self, VALUE unit) { CDJukebox *ptr = CDPlayerNew(NUM2INT(unit)); rb_iv_set(self, "@unit", unit); VALUE tdata = Data_Wrap_Struct(self, 0, cd_free, ptr); return tdata; } I suspect that its because tdata will be a class and not an object? But, the thing is, the below does work: static VALUE cd_init(VALUE self, VALUE unit) { CDJukebox *ptr = CDPlayerNew(NUM2INT(unit)); rb_iv_set(self, "@unit", unit); VALUE tdata = Data_Wrap_Struct(rb_cObject, 0, cd_free, ptr); rb_iv_set(self, "@jukebox", tdata); return self; } static VALUE cd_seekTime(VALUE self) { double tm; CDJukebox *ptr; Data_Get_Struct(rb_iv_get(self, "@jukebox"), CDJukebox, ptr); tm = CDPlayerAvgSeekTime(ptr); return rb_float_new(tm); } I don't get why the former doesn't work and the below does? Well, any insight would be helpful. Thanks, -- Norman