The second piece of code you tried is almost right. The problem is that private works in the context of instance methods instead of class methods.
To work private or private :new , you just need to force it to be in the context of class methods like this:
class A class << self private :new end end
Or if you really want to override new and call super
class A class << self private def new(*args) super(*args)
The methods of the factory class class can access the closed new simply, but trying to instantiate directly with new will fail because new is private.
Nathan Sep 30 '15 at 18:50 2015-09-30 18:50
source share