1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Use ruby2_keywords to pass keyword arguments correctly in delegation

Relocate ruby2_keywords gem dependency and `require` line 


Condition use of ruby2_keywords to avoid introducing gem dependency


Drop superfluous newline
This commit is contained in:
Andrew Blake 2021-03-25 12:43:28 +00:00
parent 15d8aca0d7
commit e767648e06

View file

@ -1943,10 +1943,12 @@ module Sinatra
module Delegator #:nodoc:
def self.delegate(*methods)
methods.each do |method_name|
define_method(method_name) do |*args, **options, &block|
return super(*args, **options, &block) if respond_to? method_name
Delegator.target.send(method_name, *args, **options, &block)
define_method(method_name) do |*args, &block|
return super(*args, &block) if respond_to? method_name
Delegator.target.send(method_name, *args, &block)
end
# ensure keyword argument passing is compatible with ruby >= 2.7
ruby2_keywords(method_name) if respond_to?(:ruby2_keywords, true)
private method_name
end
end