Module CacheMethodsModule
In: lib/modules/cache_methods_module.rb

Does not currently cache (or work at all), but the method has been tested…

Methods

Classes and Modules

Module CacheMethodsModule::ClassMethods

External Aliases

myfun -> __myfun__cached
__myfun__set_cache -> myfun
myfun -> __myfun

Public Class methods

[Source]

    # File lib/modules/cache_methods_module.rb, line 43
43:   def self.included(base)
44:     base.extend(ClassMethods)
45:   end

Public Instance methods

[Source]

    # File lib/modules/cache_methods_module.rb, line 58
58:       def __myfun__cached
59:         return @myf
60:       end
__myfun__set_cache()

Alias for myfun

Test-implementation, make it work like this…

[Source]

    # File lib/modules/cache_methods_module.rb, line 51
51:   def __to_use_as_reset_cache
52:     if self.respond_to?(:__myfun)
53:       alias :__myfun__cached :myfun
54:       alias :myfun :__myfun__set_cache
55:     else
56:       alias :__myfun :myfun
57: 
58:       def __myfun__cached
59:         return @myf
60:       end
61: 
62:       # __myfun__set_cache
63:       def myfun
64:         @myf = __myfun
65:         alias :__myfun__set_cache :myfun
66:         alias :myfun :__myfun__cached
67:         myfun
68:       end
69:     end
70:   end

[Source]

    # File lib/modules/cache_methods_module.rb, line 72
72:   def __to_use_as_testing_myfun
73:     puts "caca"
74:     return "aaaa"
75:   end
myfun()

Alias for __myfun__cached

__myfun__set_cache

[Source]

    # File lib/modules/cache_methods_module.rb, line 63
63:       def myfun
64:         @myf = __myfun
65:         alias :__myfun__set_cache :myfun
66:         alias :myfun :__myfun__cached
67:         myfun
68:       end

Initializes or resets the cache, call before using.

[Source]

    # File lib/modules/cache_methods_module.rb, line 21
21:   def reset_methods_cache(keys = [])
22:     if @cache_hash.nil?
23:       @cache_hash = {}
24:     end
25:     if keys.empty?
26:       keys = @cache_hash.keys
27:     end
28:     keys.each {|k|
29:       @cache_hash.delete(k)
30:     }
31:   end

[Validate]