Project

memoizer

0.02
No release in over 3 years
Low commit activity in last 3 years
Memoizer caches the results of your method calls, works well with methods that accept arguments or return nil. It's a simpler and more expicit alternative to ActiveSupport::Memoizable
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.4.2
~> 3.5.0
~> 0.8.0
 Project Readme

memoizer

Memoizer will memoize the results of your methods. It acts much like ActiveSupport::Memoizable without all of that freezing business. The API for unmemoizing is also a bit more explicit.

Install

$ gem install memoizer

Usage

To memoize an instance method:

class A
  include Memoizer
  def hello() 'hello!'; end
  memoize :hello
end

Or you can memoize many methods at once:

class B
  extend Memoizer
  def hello() 'hello!'; end
  def goodbye() 'goodbye :('; end
  memoize :hello, :goodbye
end

Memoizing class methods works the same way:

class C
  class << self
    include Memoizer
    def hello() 'hello!'; end
    memoize :hello
  end
end

To unmemoize a specific method:

instance = A.new
instance.hello              # the hello method is now memoized
instance.unmemoize(:hello)  # the hello method is no longer memoized
instance.hello              # the hello method is run again and re-memoized

To unmemoize all methods for an instance:

instance = B.new
instance.hello          # the hello method is now memoized
instance.goodbye        # the goodbye method is now memoized
instance.unmemoize_all  # neither hello nor goodbye are memoized anymore

License

See LICENSE.txt