Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Class#allocate

() -> untyped
class.allocate() → obj

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
See also .new #attached_object #inherited also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0