allocate()
public
Allocates space for a new object of
class’s class. The returned object must be an instance of
class.
Show source
/*
* call-seq:
* class.allocate() => obj
*
* Allocates space for a new object of <i>class</i>'s class. The
* returned object must be an instance of <i>class</i>.
*
*/
VALUE
rb_obj_alloc(klass)
VALUE klass;
{
VALUE obj;
if (RCLASS(klass)->super == 0) {
rb_raise(rb_eTypeError, "can't instantiate uninitialized class");
}
if (FL_TEST(klass, FL_SINGLETON)) {
rb_raise(rb_eTypeError, "can't create instance of virtual class");
}
obj = rb_funcall(klass, ID_ALLOCATOR, 0, 0);
if (rb_obj_class(obj) != rb_class_real(klass)) {
rb_raise(rb_eTypeError, "wrong instance allocation");
}
return obj;
}