Which Ruby memoize pattern does ActiveSupport::Memoizable refer to?

前端 未结 4 896
忘掉有多难
忘掉有多难 2021-01-30 16:14

So in Rails 3.2, ActiveSupport::Memoizable has been deprecated.

The message reads:

DEPRECATION WARNING: ActiveSupport::Memoizable is deprecated and
will          


        
4条回答
  •  不要未来只要你来
    2021-01-30 16:52

    Just an addition to the top answer, to memoize a class method use the following pattern:

    class Foo
      class << self
        def bar
          @bar ||= begin
            # ...
          end
        end
      end
    end
    

提交回复
热议问题