-
-
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
Deprecate Path#dirname #7762
Deprecate Path#dirname #7762
Conversation
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.
I think that makes sense, the dirname still is a path. Didn't see Path#parent
I'am confused, what's the difference between Edit: that's the same, |
@j8r I guess I do agree that it might be confusing. So in your case you can do I'd also like to see |
With |
But having I've added a deprecation for |
True @j8r, another solution would be to make Or add |
No @bew, because:
|
I vote to close this. There's nothing wrong with |
I think it's confusing, others can be too like me. Any good reason to have both? |
One returns a string, which is familiar and known from File.dirname, the other one returns a Path. Why force users to write to_s when they can simply get something with one method call? |
The user that is familiar with |
Co-Authored-By: Sijawusz Pur Rahnama <[email protected]>
Yes, the result of
|
Maybe one day all paths would be represented as |
Here is the use case I faced, how to get the directory name?
With either
File.basename(File.dirname(Dir.current))
or
Path.new(Path.new(Dir.current).dirname).basename.to_s
or a mix of both.
One can also use this, but this isn't as clear nor as efficient:
Path.new(Dir.current).parts.last.lchop
Now, one can do:
Path.new(Dir.current).dirname.basename.to_s
and the root directory of the current one:
Path.new(Dir.current).dirname.dirname.basename.to_s
If a
String
is wanted,#to_s
can still be called.EDIT: There is already
Path#parent
, deprecatingPath#dirname