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

Ruby 2: use __dir__ instead of File.dirname(__FILE__) #1341

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@olleolleolle
Member

olleolleolle commented Aug 26, 2017

This PR is a search-and-replace of File.dirname(__FILE__), replacing it with the Kernel#__dir__ method introduced in Ruby 2.0.

The gemspec lists an even newer version of Ruby as a lowest-required, so there ought to be support for this.

A detail, which may matter: the return value is a little different: "The return value equals to File.dirname(File.realpath(__FILE__))."

The test suite passes.

@zzak zzak added the Wishlist label Oct 29, 2017

@zzak zzak added this to the Beyond milestone Oct 29, 2017

@zzak

This comment has been minimized.

Show comment
Hide comment
@zzak

zzak Oct 29, 2017

Member

Tagging as beyond, want to wrap up all of these kind of PRs in the next MINOR version probably

Member

zzak commented Oct 29, 2017

Tagging as beyond, want to wrap up all of these kind of PRs in the next MINOR version probably

@namusyaka namusyaka modified the milestones: Beyond, v2.1.0 Feb 19, 2018

@dentarg

This comment has been minimized.

Show comment
Hide comment
@dentarg

dentarg Jun 7, 2018

@olleolleolle what is the reason for preferring Kernel#__dir__ over File.dirname(__FILE__)? Just curious, as I couldn't understand it from the docs (https://ruby-doc.org/core-2.5.1/Kernel.html#method-i-__dir__, http://ruby-doc.org/core-2.5.1/File.html#method-c-dirname)

@zzak why MINOR? if you are unsure about this breaking anything, why not go for MAJOR? if you are sure this wont break anything, PATCH sounds good to me

dentarg commented Jun 7, 2018

@olleolleolle what is the reason for preferring Kernel#__dir__ over File.dirname(__FILE__)? Just curious, as I couldn't understand it from the docs (https://ruby-doc.org/core-2.5.1/Kernel.html#method-i-__dir__, http://ruby-doc.org/core-2.5.1/File.html#method-c-dirname)

@zzak why MINOR? if you are unsure about this breaking anything, why not go for MAJOR? if you are sure this wont break anything, PATCH sounds good to me

@olleolleolle

This comment has been minimized.

Show comment
Hide comment
@olleolleolle

olleolleolle Jun 7, 2018

Member

@dentarg It's a convenience for this specific very common use-case. It reads nicely, and Ruby provides it.

(The Rubocop community likes it, sometimes, too:Style/ExpandPathArguments.)

Member

olleolleolle commented Jun 7, 2018

@dentarg It's a convenience for this specific very common use-case. It reads nicely, and Ruby provides it.

(The Rubocop community likes it, sometimes, too:Style/ExpandPathArguments.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment