Use Memoizer instead of ActiveSupport::Memoizable

Posted Almost 12 years ago. Visible to the public.

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

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+.

Henning Koch
Last edit
Over 7 years ago
Arne Hartherz
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2012-07-02 18:22)