Read more

Use Memoizer instead of ActiveSupport::Memoizable

Henning Koch
July 02, 2012Software engineer at makandra GmbH

ActiveSupport::Memoizable will be removed from Rails and has a lot of strange caveats that will ruin your day.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Use the Memoizer gem Show archive.org snapshot instead. It works in all past and future Railses and has none of the annoying "features" of ActiveSupport::Memoizable. It just does memoization and does it well.

The syntax is similiar also:

class Foo
  include Memoizer
  
  def bar
      ...
  end
  
  memoize :bar
  
end

If you're using Ruby 2.1+, you can write this even shorter:

class Foo
  include Memoizer
  
  memoize def bar
      ...
  end

end

This is because def returns the method name as a symbol Show archive.org snapshot in 2.1+.

Posted by Henning Koch to makandra dev (2012-07-02 20:22)