什麼是保護屬性的最佳方式?請參閱以下幾點:保護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