title: Memoize multi-line method - Rails
body: <p>I've never implemented memoization before using rails, and I think I came across a good use case for it but I'm not sure how to do it. Here is what I'm working with:</p>
  
  <h3>METHOD:</h3>
  
  <pre><code> def manager_rep_code_and_name
      manager = []
  
      rep_code_list.each do |rep_code|
        context = Finfolio::GetManagerByRepCode.call(rep_code: rep_code)
  
        manager.push({name: context.manager.response.first["Name"], rep_code: rep_code})
      end
  
      manager
    end
  </code></pre>
  
  <p>This method makes a network call and can potentially take awhile to figure all this out. Is there a way I can <code>memoize</code> this method so if it already exists I don't have to go out and make this request again.</p>
  
  <h3>Something like this:</h3>
  
  <pre><code>def manager_rep_code_and_name
     @managers ||= manager = []
  
     rep_code_list.each do |rep_code|
       context = Finfolio::GetManagerByRepCode.call(rep_code: rep_code)
  
       manager.push({name: context.manager.response.first["Name"], rep_code: rep_code})
     end
  
    manager
  end
  </code></pre>
  
  <p>Obviously, that doesn't work but I'm a bit stuck at the moment.</p>