Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Class#allocate
class.allocate() → obj
object.c
View on GitHub ↗
static VALUE
rb_class_alloc_m(VALUE klass)
{
rb_alloc_func_t allocator = class_get_alloc_func(klass);
if (!rb_obj_respond_to(klass, rb_intern("allocate"), 1)) {
rb_raise(rb_eTypeError, "calling %"PRIsVALUE".allocate is prohibited",
klass);
}
return class_call_alloc_func(allocator, klass);
}
Allocates space for a new object of class’s class and does not call initialize on the new instance. The returned object must be an instance of class.
Example
klass = Class.new do def initialize(*args) @initialized = true end def initialized? @initialized || false end end klass.allocate.initialized? #=> false