什么是保护属性的最佳方式?请参阅以下几点:保护ruby对象属性不被访问
class Document
# no method outside this class can access this directly. If they call document.data, error should be thrown. including in any rendering
field sensitive_data
# but this method can be accessed by anyone
def get_sensitive_data
# where I apply the right protection
end
end
我认为'受保护的'关键字做你需要的。 – 2013-03-25 07:02:59