Question

I am upgrading an app from Rails 3.2.11 to 3.2.17 and I'm getting the following error message:

DEPRECATION WARNING: ActiveSupport::Memoizable is deprecated and will be removed in future releases, simply use Ruby memoization pattern instead.

I know what memoization is, and the offending code appears to be the following:

def api
  @client.vm_by_name(name) if cluster
end
memoize :api

I'm not quite sure how to memoize this using a ruby memoization pattern. The previous techs have memoized the api method. Anyone got any ideas?

Was it helpful?

Solution

Use this:

def api
  @api ||= @client.vm_by_name(name) if cluster
end

Note on thread safety.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top