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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)