module Memoizable::ModuleMethods
Methods mixed in to memoizable singleton classes
Public Instance Methods
freezer()
click to toggle source
Return default deep freezer
@return [#call]
@api private
# File lib/memoizable/module_methods.rb, line 12 def freezer Freezer end
memoize(*methods)
click to toggle source
Memoize a list of methods
@example
memoize :hash
@param [Array<Symbol>] methods
a list of methods to memoize
@return [self]
@api public
# File lib/memoizable/module_methods.rb, line 27 def memoize(*methods) methods.each(&method(:memoize_method)) self end
memoized?(name)
click to toggle source
Test if an instance method is memoized
@example
class Foo include Memoizable def bar end memoize :bar end Foo.memoized?(:bar) # true Foo.memoized?(:baz) # false
@param [Symbol] name
@return [Boolean]
true if method is memoized, false if not
@api private
# File lib/memoizable/module_methods.rb, line 52 def memoized?(name) memoized_methods.key?(name) end
unmemoized_instance_method(name)
click to toggle source
Return unmemoized instance method
@example
class Foo include Memoizable def bar end memoize :bar end Foo.unmemoized_instance_method(:bar)
@param [Symbol] name
@return [UnboundMethod]
the memoized method
@raise [NameError]
raised if the method is unknown
@api public
# File lib/memoizable/module_methods.rb, line 79 def unmemoized_instance_method(name) memoized_methods[name].original_method end
Private Instance Methods
included(descendant)
click to toggle source
Hook called when module is included
@param [Module] descendant
the module including ModuleMethods
@return [self]
@api private
Calls superclass method
Memoizable.included
# File lib/memoizable/module_methods.rb, line 93 def included(descendant) super descendant.module_eval { include Memoizable } end
memoize_method(method_name)
click to toggle source
Memoize the named method
@param [Symbol] method_name
a method name to memoize
@return [undefined]
@api private
# File lib/memoizable/module_methods.rb, line 106 def memoize_method(method_name) memoized_methods[method_name] = MethodBuilder.new( self, method_name, freezer ).call end
memoized_methods()
click to toggle source
Return method builder registry
@return [Hash<Symbol, MethodBuilder>]
@api private
# File lib/memoizable/module_methods.rb, line 119 def memoized_methods @_memoized_methods ||= Memory.new end