Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kwargs delegation for redis 4.2.0 with Ruby 2.8.0-dev #170

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion lib/redis/namespace.rb
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down