Private module methods in Ruby

后端 未结 9 1064
深忆病人
深忆病人 2020-12-04 06:21

I have a two part question

Best-Practice

  • I have an algorithm that performs some operation on a data structure using the public interfa
9条回答
  •  攒了一身酷
    2020-12-04 07:03

    Unfortunately, private only applies to instance methods. The general way to get private "static" methods in a class is to do something like:

    class << self
      private
    
      def foo()
       ....
      end
    end
    

    Admittedly I haven't played with doing this in modules.

提交回复
热议问题