Skip to content

Do not pollute the global namespace - #7200

Closed
BertramScharpf wants to merge 1 commit into
ruby:masterfrom
BertramScharpf:master-bsch
Closed

BertramScharpf wants to merge 1 commit into
ruby:masterfrom
BertramScharpf:master-bsch

Conversation

@BertramScharpf

@BertramScharpf BertramScharpf commented Nov 28, 2023 •

Copy link
Copy Markdown

Inside a Gem executable you get:

TOPLEVEL_BINDING.local_variables    #=> [:version, :str]

This is not fair.

I decided to propose an Object#tap call because defining a function would pollute TOPLEVEL_BINDING.private_methods.

Maybe an even better way to solve the problem is to put the variable assignments and usage into a module Gem ; ... ; end block.

@welcome

welcome Bot commented Nov 28, 2023

Copy link
Copy Markdown

Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality.

We use GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions in the PR status window below.

If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #rubygems or #bundler channel on Slack.

For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide

@hsbt

hsbt commented Nov 28, 2023

Copy link
Copy Markdown
Member

What's your issue?

@BertramScharpf

Copy link
Copy Markdown
Author

What's your issue?

It's not a technical problem. It's a matter of style. My understanding of good programming style is to leave with a clean global name space.

martinemde
martinemde previously approved these changes Nov 29, 2023

@martinemde martinemde left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand your concern is that a gem executable could not rely on str or version being unaltered in the top level namespace. You would need to compensate for this if you had a very strict need. However given that this is a critical path for every gem executable, I would suggest we need a better reason for changing it than style alone.

Comment thread lib/rubygems/installer.rb
Comment on lines +771 to +773
if ARGV.first =~ /\\A_(.*)_\\z/
str = $1
if Gem::Version.correct?(str)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This code is not strictly equivalent to the original code. I don't know with certainty that it would cause any problem, but this is a critical path for almost everything in ruby.

@martinemde
martinemde self-requested a review November 29, 2023 05:57
@martinemde
martinemde dismissed their stale review November 29, 2023 05:58

Accidentally submitted approve when I meant to comment.

@martinemde
martinemde removed their request for review November 29, 2023 05:59
@martinemde

Copy link
Copy Markdown
Contributor

I'm going to close this for now. The two proposed solutions, tap, and evaling within a module, affect the stack in unfavorable ways, imho, and solve for something that we don't think is a problem. I'm open to this issue being raised again if there's a concern or a case where this is a problem.

@martinemde martinemde closed this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants