How we work

Use self to declare class methods

We prefer using self.method_name instead of the class << self way of defining class methods.

1class Apple
2  def is_green?
3  end
5  class << self
6    def all_apples
7    end
8  end
10  def another_method
11  end

When reading this class with the number of methods defined, it's hard to tell the difference between a class method and an instance method when the methods are using class << self.

1class Apple
2  def is_green?
3  end
5  def self.all_apples
6  end
8  def another_method
9  end

Here, the class method is clearly defined and there is no ambiguity when reading this class. Moreover, it is now easier to refactor and maintain.