Ruby class with static method calling a private method?

前端 未结 3 1231
春和景丽
春和景丽 2021-02-03 21:56

I have a class with a number of static methods. Each one has to call a common method, but I\'m trying not to expose this latter method. Making it private would only allow acce

3条回答
  •  逝去的感伤
    2021-02-03 22:22

    Or as of Ruby 2.1:

    class Foo
      def self.bar
        do_calc
      end
    
      private_class_method def self.do_calc
        #...
      end
    end
    

提交回复
热议问题