module Adamantium::ModuleMethods

Methods mixed in to adamantium modules

Public Instance Methods

freezer() click to toggle source

Return default deep freezer

@return [Freezer::Deep]

@api private

# File lib/adamantium/module_methods.rb, line 13
def freezer
  Freezer::Deep
end
memoize(*methods) click to toggle source

Memoize a list of methods

@example

memoize :hash

@param [Array<#to_s>] methods

a list of methods to memoize

@return [self]

@api public

# File lib/adamantium/module_methods.rb, line 28
def memoize(*methods)
  options        = methods.last.kind_of?(Hash) ? methods.pop : {}
  method_freezer = Freezer.parse(options) || freezer
  methods.each { |method| memoize_method(method, method_freezer) }
  self
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
# File lib/adamantium/module_methods.rb, line 45
def included(descendant)
  super
  descendant.module_eval { include Adamantium }
end
memoize_method(method_name, freezer) click to toggle source

Memoize the named method

@param [Symbol] method_name

a method name to memoize

@param [#call] freezer

a callable object to freeze the value

@return [undefined]

@api private

# File lib/adamantium/module_methods.rb, line 60
def memoize_method(method_name, freezer)
  memoized_methods[method_name] = Memoizable::MethodBuilder
    .new(self, method_name, freezer).call
end