0
考慮下面的例子訪問內部負荷的資源/傾倒
module DataMapper
class Property
class CustomType < DataMapper::Property::Text
def load(value)
# do stuff and return formatted value
end
end
end
end
Class A
property :name, String
property :value, CustomType
end
現在,當我做A.first
或A.first.value
的load
方法被執行,但我需要裏面load
做的計算依賴於該實例的name
屬性。那麼如何在加載方法中獲取此實例/資源的上下文(如源代碼中所提及的)?
如果問題尚不清楚,請讓我知道!
你在'load'裏面實際做了什麼樣的「東西」? – toro2k
https://github.com/datamapper/dm-core/issues/255 –
而不是嘗試訪問load方法中的'name'屬性,您可能想要編輯'name'屬性的setter(在一個類),所以它有一個回調函數,用來設置'value'屬性。 – user1376019