Skip to content

Commit

Permalink
Fix remaining rubocop failures
Browse files Browse the repository at this point in the history
  • Loading branch information
obrie committed Dec 16, 2024
1 parent 88c879d commit dbc3783
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/memery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def fresh?(ttl)

def define_memoized_method!(klass, method_name, condition: nil, ttl: nil)
original_visibility = method_visibility(klass, method_name)
original_arity = klass.instance_method(method_name).arity
use_hashed_arguments = self.use_hashed_arguments

define_method(method_name) do |*args, &block|
Expand All @@ -85,14 +84,8 @@ def define_memoized_method!(klass, method_name, condition: nil, ttl: nil)
end

cache_store = (@_memery_memoized_values ||= {})
cache_key =
if original_arity.zero? || args.empty?
method_name
elsif use_hashed_arguments
[method_name, *args].hash
else
[method_name, *args]
end
cache_key = args.empty? ? method_name : [method_name, *args]
cache_key = cache_key.hash if use_hashed_arguments && !args.empty?
cache = cache_store[cache_key]

return cache.result if cache&.fresh?(ttl)
Expand Down

0 comments on commit dbc3783

Please sign in to comment.