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

#freezeObject

Freeze the object

Examples:

object.freeze  # object is now frozen

Returns:

  • (Object)


16
17
18
19
# File 'lib/memoizable/instance_methods.rb', line 16

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)


32
33
34
35
# File 'lib/memoizable/instance_methods.rb', line 32

def memoize(data)
  memoized_method_cache.set(data)
  self
end