public Method

Class.allocate

class.allocate()      obj

Allocates space for a new object of class’s class. The returned object must be an instance of class.

Source Code

/*
*  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;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.