这个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
是否存在性能问题?
https://stackoverflow.com/questions/10964081
复制相似问题