这Ruby Style Guide表示使用self.method_name
比使用class method_name
更好.但为什么呢?
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
是否存在性能问题?