From ca090c098c5cc17d7e7107ae947b55759be72cde Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Fri, 22 Aug 2025 14:35:40 +0200 Subject: [PATCH] Support Ruby 3 kwyword arguments in macro-style definition Fixes #46 --- lib/redis_mutex/macro.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/redis_mutex/macro.rb b/lib/redis_mutex/macro.rb index f8bad94..f8010cb 100644 --- a/lib/redis_mutex/macro.rb +++ b/lib/redis_mutex/macro.rb @@ -35,9 +35,9 @@ def method_added(target) raise ArgumentError, "You are trying to lock on unknown arguments: #{unknown_arguments.join(', ')}" end - define_method(with_method) do |*args| + define_method(with_method) do |*args, **kwargs| named_arguments = Hash[target_argument_names.zip(args)] - arguments = mutex_arguments.map { |name| named_arguments.fetch(name) } + arguments = mutex_arguments.map { |name| named_arguments.fetch(name) } + kwargs.values key = format( "%s#%s:%s", class: self.class.name, @@ -46,10 +46,10 @@ def method_added(target) ) begin RedisMutex.with_lock(key, options) do - send(without_method, *args) + send(without_method, *args, **kwargs) end rescue RedisMutex::LockError - send(after_method, *args) if respond_to?(after_method) + send(after_method, *args, **kwargs) if respond_to?(after_method) end end