Class: Makitzo::MemoizedProc

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ MemoizedProc

Returns a new instance of MemoizedProc.



3
4
5
# File 'lib/makitzo/memoized_proc.rb', line 3

def initialize(&block)
  @proc = block
end

Instance Method Details

#call(*args) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/makitzo/memoized_proc.rb', line 7

def call(*args)
  if defined?(@value)
    @value
  else
    @value = @proc.call(*args)
  end
end