Comments (7)
I've proposed a fix in #1506 if you all want to take a look.
from faraday.
Thank you @yykamei for the eye-opening explanation and @mattbrictson for providing a fix 🙇
from faraday.
This is caused by defining methods with the same name as Struct
members.
❯ 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 X
was defined by inheriting from Struct.new(:a, :b)
. I'm not sure about Ruby's internal implementation, but I guess the difference between them is the timing of the method definition. Previously, a redefined method was declared as a method of the subclass, which is just a normal overriding.
# 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 Struct
. This means that defining methods from Struct
members as well as custom methods within a block of .new
is happening at the same time.
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
from faraday.
Thank you all ❤️
from faraday.
I'm also seeing this in Faraday 2.7.5 and not in 2.7.4.
from faraday.
This is probably a side-effect of #1489 and #1491 (cc @bdewater).
The warnings don't hurt, but I'd prefer them to go away as well if possible.
I don't like that memoized
stuff going on in there and I'm not sure I fully understand why we need it, I'll need some time to look into this 👀
from faraday.
If possible, it might be the best to avoid defining the same name as Struct
members (e.g., user
should be renamed). However, such methods might be used by other plugins or applications, so another approach would be required.
from faraday.
Related Issues (20)
- Faraday::Response - argument order causes unexpected behaviour HOT 3
- Incompatible with Firebase-admin-sdk HOT 1
- Streaming Stop with Connection Close? HOT 3
- `Faraday::Request::Json` doesn't encode the value `false` while it encodes `true` to `"true"` HOT 2
- Faraday using PUT with Transfer-Encoding: chunked
- Faraday::ParsingError.response_status doesn't return expected value when stubbing response HOT 5
- Missing HTTP 408 Request Timeout specific Faraday ClientError? HOT 3
- Dead link to Faraday Team in README and docs HOT 1
- Strange behaviour with response HOT 1
- Setting ActiveRecord DatabaseResolver to enable multi database does not work with Faraday adapter HOT 3
- Unable to use webdav verbs HOT 3
- Change connection proxy HOT 2
- Drop Ruby < 3.0 support HOT 1
- `no_proxy` Parameter in Manual Proxy Configuration HOT 4
- connection headers are ignored when using build_response directly HOT 5
- Add tests and documentation to make sure adapters support streaming requests HOT 2
- Any solution for Digest Auth in Faraday 2? HOT 2
- Case Insensitivity Issue with #dig Method on Response Headers HOT 1
- Test friction HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faraday.