私有类方法

要让你的类方法变得私有,你需要使用 private_class_method :method_name 或者把你的私有类方法放到class << self block 中:

class Foo

  class << self
    private    
    def bar
      puts 'Class method called'
    end    
  end

  def self.baz
    puts 'Another class method called'
  end
  private_class_method :baz

end

Foo.bar # => NoMethodError: private method `bar' called for Foo:Class
Foo.baz # => NoMethodError: private method `baz' called for Foo:Class
原文地址:https://www.cnblogs.com/qinyan20/p/3713674.html