Hi,
In message "[ruby-talk:01874] object creation"
on 00/03/15, Andrew Hunt <Andy / Toolshed.Com> writes:
|Just a quick question -- is the following sequence the correct
|way to create a Ruby object from C?
|
| NEWOBJ(obj, c-type) -- allocate memory for an object
| OBJSETUP(obj, class, T_class); -- set appropriate flags
| rb_obj_call_init(obj, argc, argv); -- call initialize
Yes. But I think it's better for T_DATA object to use
Data_Make_Struct/Data_Wrap_Struct, as Clemens stated.
|There was some discussion a while back on whether *every* class called
|initialize or not, how did that end up? It would apper from the
|current code that most of the built-in classes *do not* call
|an initialize method.
I made several classes to call `initialize', such as Array, Range,
Dir, etc. But still wondering whether *every* class calls `initialize'
or not, for cases the arguments to `new' used for allocation.
matz.