I am fighting with singleton patterns in Ruby.
I know that singleton implements a single instance of an object but I don't quite understand if we can replicate it without the singleton module.
Then there is the issue with private methods; Right now I have to do something like this:
class MyTestClass
private_class_method :new
class << self
def test
puts hello
end
private
def hello
'hello world'
end
end
end
MyTestClass.test
So my questions are:
- Is the above a good Singleton pattern?
- Would this make sure there is only a single instance?
- Is there a way to have private methods using the singleton module?