lib/pakiderm.rb
# Public: Adds memoization to methods without parameters using Module#prepend.
#
# names - Names of the methods to be memoized.
#
# Examples
#
#   memoize :ready?, :complex_formula, :long_running_method!
#
# Returns nothing.
Adds memoization to methods without parameters using Module#prepend.
names - Names of the methods to be memoized.

Examples



Returns nothing.
Adds memoization to methods without parameters using Module#prepend . names - Names of the methods to be memoized . Examples Returns nothing .
def memoize(*names)
    prepend Module.new {
      names.each do |name|
        ivar = Pakiderm.memoized_ivar_for(name)
        define_method(name) {
          if instance_variable_defined?(ivar)
            instance_variable_get(ivar)
          else
            instance_variable_set(ivar, super())
          end
        }
      end
    }
  end
def memoize ( * names ) prepend Module . new { names . each do | name | ivar = Pakiderm . memoized_ivar_for ( name ) define_method ( name ) { if instance_variable_defined? ( ivar ) instance_variable_get ( ivar ) else instance_variable_set ( ivar , super ( ) ) end } end } end
Public: Adds memoization to methods without parameters using Module#prepend.
Public : Adds memoization to methods without parameters using Module#prepend .
names
<not_specific>