문제

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?

도움이 되었습니까?

해결책

Use this:

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

Note on thread safety.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top