Module: Memoizable::InstanceMethods

Included in:
Memoizable
Defined in:
lib/memoizable/instance_methods.rb

Overview

Methods mixed in to memoizable instances

Instance Method Summary collapse

Instance Method Details

#freeze ⇒ Object

Freeze the object

Examples:

object.freeze  # object is now frozen

Returns:

  • (Object)


14
15
16
17
# File 'lib/memoizable/instance_methods.rb', line 14

def freeze
  memoized_method_cache # initialize method cache
  super
end

#memoize(data) ⇒ self

Sets a memoized value for a method

Examples:

object.memoize(hash: 12345)

Parameters:

  • data (Hash{Symbol => Object}) —

    the data to memoize

Returns:

  • (self)


30
31
32
33
# File 'lib/memoizable/instance_methods.rb', line 30

def memoize(data)
  data.each { |name, value| memoized_method_cache.store([self.class, name], value) }
  self
end