I tried to implement a singleton pattern in ruby, just want to know why I can not access private class method in ruby
class Test private_class_method :new @@instance = nil def self.getInstance if(!@@instance) @@instance = Test.new end return @@instance end end I declare "new" as a private class method, and try to call the "new" in my singleton method "getInstance"
test output
>> require "./test.rb" => true >> Test.getInstance NoMethodError: private method `new' called for Test:Class from ./test.rb:7:in `getInstance' from (irb):2 >>
newwith a receiver because it is now private. And it is you who made it private. Not clear why you are doing such contradictory thing and wondering over it.