1
class Curious
def calculation
def calculation
@retrieved_value
end
@retrieved_value = #some kind of intensive process
end
end
這樣做,外部方法將在第一次運行,內部方法將提供值的後續時間。在一個非嵌套方法中做這件事的優點或缺點是什麼@retrieved_value ||= #some kind of intensive process
?Ruby範圍化的方法值技術
「嵌套方法」可能是一個壞名詞,因爲該方法在「封閉」方法的範圍之外是可用的。 –