This Ruby Style Guide tells that is better using self.method_name instead of class method_name. But Why?
class TestClass
# bad
class << self
def first_method
# body omitted
end
def second_method_etc
# body omitted
end
end
# good
def self.first_method
# body omitted
end
def self.second_method_etc
# body omitted
end
end
Are there performance issues?
class << selfis good at keeping all of your class methods in the same block. If methods are being added indef self.methodform then there’s no guarantee (other than convention and wishful thinking) that there won’t be an extra class method tucked away later in the file.def self.methodis good at explicitly stating that a method is a class method, whereas withclass << selfyou have to go and find the container yourself.Which of these is more important to you is a subjective decision, and also depends on things like how many other people are working on the code and what their preferences are.