Module: Adamantium::ModuleMethods

Defined in:
lib/adamantium/module_methods.rb

Overview

Methods mixed in to adamantium modules

Instance Method Summary collapse

Instance Method Details

#freezerFreezer::Deep

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return default deep freezer

Returns:



27
28
29
# File 'lib/adamantium/module_methods.rb', line 27

def freezer
  Freezer::Deep
end

#included(mod) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hook called when module is included

Parameters:

  • mod (Module)

    the module including ModuleMethods

Returns:

  • (self)


16
17
18
19
# File 'lib/adamantium/module_methods.rb', line 16

def included(mod)
  Adamantium.included(mod)
  self
end

#memoize(*methods) ⇒ self

Memoize a list of methods

Examples:

memoize :hash

Parameters:

  • methods (Array<#to_s>)

    a list of methods to memoize

Returns:

  • (self)


42
43
44
45
46
47
# File 'lib/adamantium/module_methods.rb', line 42

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

#original_instance_method(name) ⇒ UnboundMethod

Return original instance method

Examples:


class Foo
  include Adamantium

  def bar
  end
  memoize :bar

end

Foo.original_instance_method(:bar) #=> UnboundMethod, where source_location still points to original!

Parameters:

  • name (Symbol)

Returns:

  • (UnboundMethod)

    if method was memoized before

Raises:

  • (ArgumentError)

    otherwise



74
75
76
# File 'lib/adamantium/module_methods.rb', line 74

def original_instance_method(name)
  memoized_methods[name]
end