Class: Module

Inherits:
Object show all
Defined in:
lib/lab42/core/fn.rb,
lib/lab42/core/memoization.rb

Overview

class Object

Instance Method Summary collapse

Instance Method Details

#fmObject



10
11
12
# File 'lib/lab42/core/fn.rb', line 10

def fm
  Lab42::Behavior::Proxy.new self, fm: true
end

#memoize(sym) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/lab42/core/memoization.rb', line 3

def memoize sym
  orig_method = instance_method sym
  define_method sym do |*args|
    ivar_name = "@__#{sym}__" 
    instance_variable_set ivar_name, {} unless instance_variable_defined? ivar_name
    instance_variable_get( ivar_name ).fetch! args do
      # Not cached yet!!!
      orig_method.bind( self ).( *args )
    end
  end
end