Skip to content
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

New gem template: prefer require_relative to require #4066

Merged
merged 1 commit into from Nov 17, 2020

Conversation

marcandre
Copy link
Contributor

New gem template uses require_relative in the gemspec but require in the lib/gem.rb. This PR changes that second occurrence.

@marcandre marcandre marked this pull request as draft November 17, 2020 04:07
@marcandre
Copy link
Contributor Author

Mmm, that's incorrect in case of bundle gem with-dash though.

@marcandre marcandre marked this pull request as ready for review November 17, 2020 05:09
@marcandre
Copy link
Contributor Author

Should be fixed, tests too 😅

Copy link
Member

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @marcandre!

@deivid-rodriguez deivid-rodriguez merged commit 13bce26 into rubygems:master Nov 17, 2020
deivid-rodriguez added a commit that referenced this pull request Dec 7, 2020
New gem template: prefer `require_relative` to `require`

(cherry picked from commit 13bce26)
deivid-rodriguez added a commit that referenced this pull request Dec 7, 2020
New gem template: prefer `require_relative` to `require`

(cherry picked from commit 13bce26)
deivid-rodriguez added a commit that referenced this pull request Dec 7, 2020
New gem template: prefer `require_relative` to `require`

(cherry picked from commit 13bce26)
deivid-rodriguez added a commit that referenced this pull request Dec 7, 2020
New gem template: prefer `require_relative` to `require`

(cherry picked from commit 13bce26)
@bobf
Copy link

bobf commented Dec 23, 2021

@deivid-rodriguez Can you give some info about the benefits of using require_relative over require here ?

The PR description mentions that it is to bring things in line with the .gemspec definition but the relevant commit here doesn't seem to provide any extra context and isn't linked to a PR.

Should require_relative be used for other files in the gem and are you able to explain why this is better ? Does it provide some benefits for disambiguation ?

I would appreciate any feedback so I can adapt to newer/better practices if needed.

@deivid-rodriguez
Copy link
Member

Hello!

My personal recommendation is to use require_relative for files relative to your project. That gives information to the person that reads the code that you're loading an internal dependency, not a third party one. It also has the performance benefit that it doesn't need to search the $LOAD_PATH since require_relative knows exactly where the file it needs to load is located.

@bobf
Copy link

bobf commented Dec 23, 2021

@deivid-rodriguez That makes sense - thanks a lot for the quick response. I will use this strategy in future.

Have a nice Christmas !

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

Successfully merging this pull request may close these issues.

None yet

4 participants