首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >class vs self.method with <<:哪个更好?

class vs self.method with <<:哪个更好?
EN

Stack Overflow用户
提问于 2012-06-10 03:48:32
回答 4查看 37.3K关注 0票数 68

这个Ruby Style Guide告诉我们,使用self.method_name比使用class method_name更好。但是为什么呢?

代码语言:javascript
复制
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

是否存在性能问题?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10964081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档