How to make the class constructor private in Ruby?

access-specifier, constructor, ruby

Solution

Try this:

class A
  private_class_method :new
end

More on APIDock

Problem

``` class A private def initialize puts "wtf?" end end A.new #still works and calls initialize ``` and ``` class A private def self.new super.new end end ``` doesn't work altogether So what's the correct way? I want to make `new` private and call it via a factory method.

Original source