-
Notifications
You must be signed in to change notification settings - Fork 968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lots of "warning: method redefined; discarding old" printed during testing #1505
Comments
I'm also seeing this in Faraday 2.7.5 and not in 2.7.4. |
This is caused by defining methods with the same name as ❯ cat test.rb
X = Struct.new(:a, :b) do
def a
:other
end
end
X.new(1, 2).a # => :other
❯ ruby -W test.rb
test.rb:2: warning: method redefined; discarding old a Before #1489, the above # This case just overrides the method defined by the parent class.
class X < Struct.new(:a, :b)
def a
end
end
# NOTE: The above code is the same as the below.
TMP = Struct.new(:a, :b)
class X < TMP
def a
end
end In the latest code, redefinition occurs during the setup of X = Struct.new(:a, :b) do
def a
end
end
# Defining the method within the block seems to be the same as the below.
class X
def a
end
def a
end
end |
If possible, it might be the best to avoid defining the same name as |
I've proposed a fix in #1506 if you all want to take a look. |
Thank you @yykamei for the eye-opening explanation and @mattbrictson for providing a fix 🙇 |
Thank you all ❤️ |
Basic Info
Issue description
With warnings enabled (eg during testing), there are several lines printed with "warning: method redefined; discarding old" warnings.
Steps to reproduce
The text was updated successfully, but these errors were encountered: