Class: PureFunction

Inherits:
Object
  • Object
show all
Defined in:
lib/pure_function.rb

Constant Summary collapse

@@cache =
{}

Class Method Summary collapse

Class Method Details

.cache(&block) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/pure_function.rb', line 3

def self.cache(&block)
  calling_line = caller.first
  calling_line = calling_line[0..(calling_line.index(':in')||0)-1]
  return Marshal.load(@@cache[calling_line]) if @@cache[calling_line]
  ret_val = yield
  @@cache[calling_line]=Marshal.dump(ret_val)
  return ret_val
end

.clearObject



11
12
13
# File 'lib/pure_function.rb', line 11

def self.clear
  @@cache = {}
end