如何制作受保护的单例方法

How to make a protected singleton method

如何使以下方法 some_protected 受保护或私有?应该不用继承来实现。

module Sample
  def self.some_public
    some_protected
  end

  protected

  def self.some_protected
    puts 'Bingo!'
  end
end

Sample::some_public     # Bingo!
Sample::some_protected  # Bingo! (but expected an error that method is not accessible)

在单例中工作 class 可能是最简单的。

module Sample; end

class <<Sample
  def some_public
    some_protected
  end
  protected def some_protected
    puts 'Bingo!'
  end
end