Ruby: is it acceptable to put more than one class in a file?

后端 未结 3 1676
野趣味
野趣味 2021-02-13 14:33

This might be a bit of an esoteric question, but I just want to know what best practices are on this issue.

3条回答
  •  猫巷女王i
    2021-02-13 15:02

    Yes, it is generally acceptable because it doesn't violate any principles of the Ruby language itself but it ultimately depends on the practices of your target audience or framework. (For example, Rails likes your classes to be one-per-file.)

    However, if you are grouping classes with related functionality into a single file then you should also consider making them part of the same module for a namespace.

提交回复
热议问题