Memoized
Memoized 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 memoized
Usage
To define a memoized instance method, use memoized def
`:
class A
include Memoized
memoize def hello
'hello!'
end
end
You may also memoize
one or more methods after they have been defined:
class B
include Memoized
def hello
'hello!'
end
def goodbye
'goodbye :('
end
memoize :hello, :goodbye
end
Memoizing class methods works the same way:
class C
class << self
include Memoized
memoize def hello
'hello!'
end
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