Where to place private methods in Ruby?

前端 未结 10 1130
故里飘歌
故里飘歌 2021-01-30 00:50

Most of the blogs or tutorials or books have private methods at the bottom of any class/module. Is this the best practice?

I find having private methods as and when nece

10条回答
  •  星月不相逢
    2021-01-30 01:18

    You don't need to put public or private above each method. I usually put all of my private methods at the bottom of my class. Also, don't have to explicitly say public as methods are public by default. For example:

    class FooBar
    
      def some_public_method
      end
    
      def another_public_method
      end
    
    private
    
      def some_private_method
      end
    
      def another_private method
      end
    
    end
    

提交回复
热议问题