Module: Memoizable::ModuleMethods

Defined in:
lib/memoizable/module_methods.rb

Overview

Methods mixed in to memoizable singleton classes

Instance Method Summary collapse

Instance Method Details

#freezer#call

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:

  • (#call)


13
14
15
# File 'lib/memoizable/module_methods.rb', line 13

def freezer
  Freezer
end

#memoize(*methods) ⇒ self

Memoize a list of methods

Examples:

memoize :hash

Parameters:

  • methods (Array<Symbol>)

    a list of methods to memoize

Returns:

  • (self)


28
29
30
31
# File 'lib/memoizable/module_methods.rb', line 28

def memoize(*methods)
  methods.each(&method(:memoize_method))
  self
end

#memoized?(name) ⇒ Boolean

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.

Test if an instance method is memoized

Examples:

class Foo
  include Memoizable

  def bar
  end
  memoize :bar
end

Foo.memoized?(:bar)  # true
Foo.memoized?(:baz)  # false

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)

    true if method is memoized, false if not



53
54
55
# File 'lib/memoizable/module_methods.rb', line 53

def memoized?(name)
  memoized_methods.key?(name)
end

#unmemoized_instance_method(name) ⇒ UnboundMethod

Return unmemoized instance method

Examples:


class Foo
  include Memoizable

  def bar
  end
  memoize :bar
end

Foo.unmemoized_instance_method(:bar)

Parameters:

  • name (Symbol)

Returns:

  • (UnboundMethod)

    the memoized method

Raises:

  • (NameError)

    raised if the method is unknown



80
81
82
# File 'lib/memoizable/module_methods.rb', line 80

def unmemoized_instance_method(name)
  memoized_methods[name].original_method
end