Module: Mem

Defined in:
lib/mem.rb,
lib/mem/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/mem.rb', line 6

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#has_memoized?(key) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/mem.rb', line 10

def has_memoized?(key)
  memoized_table.key?(key)
end

#memoize(key, value) ⇒ Object



14
15
16
# File 'lib/mem.rb', line 14

def memoize(key, value)
  memoized_table[key] = value
end

#memoized(key) ⇒ Object



18
19
20
# File 'lib/mem.rb', line 18

def memoized(key)
  memoized_table[key]
end

#memoized_tableObject



22
23
24
# File 'lib/mem.rb', line 22

def memoized_table
  @memoized_table ||= {}
end

#unmemoize(key) ⇒ Object



26
27
28
# File 'lib/mem.rb', line 26

def unmemoize(key)
  memoized_table.delete(key)
end