What is a good way to memoize data across many instances of a class in Ruby?
问题 Consider: many instances of an object that generates data. It would be great to only generate that data once per run. class HighOfNPeriods < Indicator def generate_data @indicator_data = DataStream.new (0..@source_data.data.count - 1).each do |i| if i < @params[:n_days] ... @indicator_data.add one_data end end There are different instances of HighOfNPeriods with different params and different @source_data . Here is how the indicator is used: class Strategy attr_accessor :indicators def