From 11ac92ef79d5943201d5b47b7a783e510b1e4067 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 18 Dec 2019 16:05:20 +0100 Subject: [PATCH] Use new ... syntax in Module#delegate if it's available It was added in https://bugs.ruby-lang.org/issues/16253 It allows to do blind delegation without having to worry about ruby2_keywords, and suposedly is also a bit faster. --- .../lib/active_support/core_ext/module/delegation.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 419c118e73965..957bb7f1a9aac 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -199,7 +199,13 @@ def delegate(*methods, to: nil, prefix: nil, allow_nil: nil, private: nil) # Attribute writer methods only accept one argument. Makes sure []= # methods still accept two arguments. - definition = /[^\]]=$/.match?(method) ? "arg" : "*args, &block" + definition = if /[^\]]=$/.match?(method) + "arg" + elsif RUBY_VERSION >= "2.7" + "..." + else + "*args, &block" + end # The following generated method calls the target exactly once, storing # the returned value in a dummy variable.