Skip to content

Commit

Permalink
Use new ... syntax in Module#delegate if it's available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
byroot committed Dec 18, 2019
1 parent 6da2152 commit 11ac92e
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -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.
Expand Down

0 comments on commit 11ac92e

Please sign in to comment.