Ruby class with static method calling a private method?

前端 未结 3 1266
春和景丽
春和景丽 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:15

    You can define a private class method with private_class_method like this:

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

提交回复
热议问题