How to make the class constructor private in Ruby?

Posted by Leonid Shevtsov on Stack Overflow See other posts from Stack Overflow or by Leonid Shevtsov
Published on 2009-10-14T16:18:53Z Indexed on 2010/05/20 1:00 UTC
Read the original article Hit count: 242

Filed under:
|
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.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about constructor