Module: Memery::ClassMethods
- Defined in:
- lib/memery.rb
Instance Method Summary collapse
- #memoize(*method_names, condition: nil, ttl: nil) ⇒ Object
- #memoized?(method_name) ⇒ Boolean
- #method_added(name) ⇒ Object
Instance Method Details
#memoize(*method_names, condition: nil, ttl: nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/memery.rb', line 40 def memoize(*method_names, condition: nil, ttl: nil) if method_names.empty? @_memery_memoize_next_method = { condition: condition, ttl: ttl } return end prepend_memery_module! method_names.each do |method_name| define_memoized_method!(method_name, condition: condition, ttl: ttl) end method_names.length > 1 ? method_names : method_names.first end |
#memoized?(method_name) ⇒ Boolean
52 53 54 55 56 57 |
# File 'lib/memery.rb', line 52 def memoized?(method_name) return false unless defined?(@_memery_module) @_memery_module.method_defined?(method_name) || @_memery_module.private_method_defined?(method_name) end |
#method_added(name) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/memery.rb', line 59 def method_added(name) super return unless @_memery_memoize_next_method memoize(name, **@_memery_memoize_next_method) @_memery_memoize_next_method = nil end |