这个Ruby风格指南告诉我们更好地使用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
Run Code Online (Sandbox Code Playgroud)
有性能问题吗?
ruby ×1