Where to place private methods in Ruby?

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

    I generally order my methods as follows:

    1. Constructor
    2. Other public methods, in alphabetical order
    3. private, written only once
    4. Private methods, in alphabetical order

    I use “go to definition” features in my editor so that this doesn’t involve much scrolling, and in any case, if the class is big enough that scrolling becomes problematic, it probably should be broken up into several classes.

提交回复
热议问题