如何使以下方法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)
答案 0 :(得分:2)
在单例类中工作可能是最简单的。
module Sample; end
class <<Sample
def some_public
some_protected
end
protected def some_protected
puts 'Bingo!'
end
end