Skip to content

Commit 8b24ec2

Browse files
committed
Avoid "method redefined" warnings in Delegator
When extensions (like sinatra-contrib) are registered, they often re-delegate methods that are already defined on the Delegator (e.g., `get`, `post`, `config_file`). This causes noisy "method redefined" warnings at runtime. This change adds a check to `Delegator.delegate` to skip defining the method if it already exists. Since the delegation logic is identical (forwarding to `Delegator.target`), skipping the redefinition is safe and eliminates the warnings.
1 parent 074d876 commit 8b24ec2

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

lib/sinatra/base.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,8 @@ def self.register(*extensions, &block) # :nodoc:
21032103
module Delegator # :nodoc:
21042104
def self.delegate(*methods)
21052105
methods.each do |method_name|
2106+
next if method_defined?(method_name) || private_method_defined?(method_name)
2107+
21062108
define_method(method_name) do |*args, &block|
21072109
return super(*args, &block) if respond_to? method_name
21082110

0 commit comments

Comments
 (0)