From 5feb9a06934e31d83fda5cdd76cf4c9688d95c00 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Wed, 10 Jun 2020 14:56:46 +0900 Subject: [PATCH] Fix kwargs delegation for redis 4.2.0 with Ruby 2.8.0-dev redis 4.2.0 with Ruby 2.8.0-dev has broken Rails CI. https://github.com/redis/redis-rb/commit/1e5d0a15f7f1e7d290b90bbd4191e5622e95b6a1 https://buildkite.com/rails/rails/builds/69984#fc71e8e4-bf32-425b-a466-6487d8fa001d/1793-1824 This allows kwargs delegation for redis 4.2.0 client. --- lib/redis/namespace.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/redis/namespace.rb b/lib/redis/namespace.rb index 56295fa..57a9c3a 100644 --- a/lib/redis/namespace.rb +++ b/lib/redis/namespace.rb @@ -348,6 +348,7 @@ def eval(*args) define_method(command) do |*args, &block| call_with_namespace(command, *args, &block) end + ruby2_keywords(command) if respond_to?(:ruby2_keywords, true) end def method_missing(command, *args, &block) @@ -486,11 +487,29 @@ def call_with_namespace(command, *args, &block) private + unless Hash.respond_to?(:ruby2_keywords_hash?) + using Module.new { + refine Hash do + class << Hash + if RUBY_VERSION >= "2.7" + def ruby2_keywords_hash?(hash) + !new(*[hash]).default.equal?(hash) + end + else + def ruby2_keywords_hash?(hash) + false + end + end + end + end + } + end + # Avoid modifying the caller's (pass-by-reference) arguments. def clone_args(arg) if arg.is_a?(Array) arg.map {|sub_arg| clone_args(sub_arg)} - elsif arg.is_a?(Hash) + elsif arg.is_a?(Hash) && !Hash.ruby2_keywords_hash?(arg) Hash[arg.map {|k, v| [clone_args(k), clone_args(v)]}] else arg # Some objects (e.g. symbol) can't be dup'd.