Skip to content

Commit

Permalink
Use ruby2_keywords to pass keyword arguments correctly in delegation
Browse files Browse the repository at this point in the history
Relocate ruby2_keywords gem dependency and `require` line 


Condition use of ruby2_keywords to avoid introducing gem dependency


Drop superfluous newline
  • Loading branch information
Andrew Blake committed Mar 25, 2021
1 parent 15d8aca commit e767648
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/sinatra/base.rb
Expand Up @@ -1943,10 +1943,12 @@ def self.register(*extensions, &block) #:nodoc:
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
Expand Down

0 comments on commit e767648

Please sign in to comment.