1

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?

stephenmurdoch
  • 34,024
  • 29
  • 114
  • 189

1 Answers1

3

Use this:

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

Note on thread safety.

Community
  • 1
  • 1
Damien Roche
  • 13,189
  • 18
  • 68
  • 96