Module: DeepCover::Memoize::ClassMethods

Defined in:
lib/deep_cover/memoize.rb

Instance Method Summary collapse

Instance Method Details

#memoize(*methods) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/deep_cover/memoize.rb', line 35

def memoize(*methods)
  @memoized = (memoized | methods).freeze

  methods.each do |method|
    memoizer_module.module_eval <<-RUBY, __FILE__, __LINE__ + 1
      def #{method}                    # def foo
        @_#{method} ||= super.freeze   #   @_foo ||= super.freeze
      end                              # end
    RUBY
  end
end

#memoizedObject



23
24
25
# File 'lib/deep_cover/memoize.rb', line 23

def memoized
  @memoized ||= [].freeze
end

#memoizer_moduleObject



27
28
29
30
31
32
33
# File 'lib/deep_cover/memoize.rb', line 27

def memoizer_module
  @memoizer_module ||= begin
    mod = const_set(:Memoizer, Module.new)
    prepend mod
    mod
  end
end