-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Use implicit #new in File.open #5337
Conversation
This should not close #5335, this fix is just about a side note in that issue. |
I've changed PR's description, even though mentioned issue is about using wrong ctor ( |
@@ -439,7 +439,7 @@ class File < IO::FileDescriptor | |||
# File.read("bar") # => "foo" | |||
# ``` | |||
def self.read(filename, encoding = nil, invalid = nil) : String | |||
File.open(filename, "r") do |file| | |||
open(filename, "r") do |file| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this case and the other below, I'm not sure it's an issue to use File.
because the returned object is not a File
.
However it's true that if someone wants to override the behavior of open
, it is needed to call the implicit open
in other class methods.. So maybe it's good, I don't know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explicit receiver is unnecessary and can be safely omitted.
@straight-shoota why not close? theres no bug, only File.new should be new |
Because the issue about |
@straight-shoota so solution is...? people make mistakes. theres no way to prevent these errors. sometimes you want File.new sometimes just new. theres nothing to fix. for some it seems everything can be fixed or must be fixed. |
@straight-shoota I believe there's no conceptual error here, just mistakenly used |
maybe he means search other places where this happens. then close issue. thats good |
@RX14 🏓 |
Thanks! |
Refs #5335