Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Class#allocate

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 #inherited #json_creatable? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1