Where to place private methods in Ruby?

前端 未结 10 1027
故里飘歌
故里飘歌 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:05

    Dennis had the perfect answer, that is, when using ruby >=2.1, just prefix the def with private (or protected,public)

    But I believe that it's now also possible to use private as a block as in:

    private begin
       def foo
       end
       def bar
       end
    end
    
    def zip
    end
    

提交回复
热议问题