matthewrudy / memoist

ActiveSupport::Memoizable with a few enhancements
MIT License
920 stars 99 forks source link

Add an interface to write to memoized ivar? #57

Closed onyxblade closed 7 years ago

onyxblade commented 7 years ago

Hi, sometimes we need to batch preload attributes like:

ivar = Memoist.memoized_ivar_for(:available_stock)
products.each do |product|
  product.instance_variable_set(ivar, xxx)
end

would it be great to be

products.each do |product|
  Memoist.set_memoized(product, :available_stock, xxx)
end

or something?

Thanks in advanced.