The definition of a method on one line should be done only in the documentation, otherwise divide it into three lines:
def method some code end
If you find that you have many methods with one liner (i.e. getters and setters), there can be many metaprogramming methods to reduce duplication (for example, using define_method
). For example, you can use :attr_accessor
to define many getters and setters:
class Person
Here is a ruby ββforum that talks about it. I also highly recommend reading Ruby Metaprogramming . It has many goodies, like 3 or 4 ways to solve your problem, as well as many other methods to reduce duplication.
source share