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范围化的方法值技术
“嵌套方法”可能是一个坏名词,因为该方法在“封闭”方法的范围之外是可用的。 –