Skip to content

Remove string mutation#3733

Open
bb wants to merge 1 commit intorailsadminteam:masterfrom
bb:patch-2
Open

Remove string mutation#3733
bb wants to merge 1 commit intorailsadminteam:masterfrom
bb:patch-2

Conversation

@bb
Copy link
Contributor

@bb bb commented Mar 14, 2026

There are a lot of warnings about a string "will be frozen in the future" (depending on the users code base).

E.g.

/Users/bb/.asdf/installs/ruby/3.4.8/lib/ruby/gems/3.4.0/gems/rails_admin-3.3.0/lib/rails_admin/config/configurable.rb:60: warning: string returned by :visible?.to_s will be frozen in the future
/Users/bb/.asdf/installs/ruby/3.4.8/lib/ruby/gems/3.4.0/gems/rails_admin-3.3.0/lib/rails_admin/config/configurable.rb:60: warning: string returned by :active?.to_s will be frozen in the future
/Users/bb/.asdf/installs/ruby/3.4.8/lib/ruby/gems/3.4.0/gems/rails_admin-3.3.0/lib/rails_admin/config/configurable.rb:60: warning: string returned by :visible?.to_s will be frozen in the future

This fixes it by not mutating the option_name string inline but explicitly reassigning.

Copilot AI review requested due to automatic review settings March 14, 2026 12:31
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates RailsAdmin’s configurable option registration to avoid in-place mutation of option_name, addressing Ruby warnings about future freezing of strings returned by Symbol#to_s.

Changes:

  • Replace chop! (mutating) with chop (non-mutating) when handling boolean option names ending in ?.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 55 to +61
option_name = option_name.to_s
options[option_name] = nil

# If it's a boolean create an alias for it and remove question mark
if option_name.end_with?('?')
scope.send(:define_method, "#{option_name.chop!}?") do
option_name = option_name.chop
scope.send(:define_method, "#{option_name}?") do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dear Copilot, thanks for your valued suggestion, but your suggestion introduces a bug that previously options[original_name] was set to nil while you're setting options[normalized_name] to nil (which wasn't there anyway). As in the original version as well as in my change, the option_name is no longer in the options hash, there's no need to change has_option?. Changing the name to normalized_name through the whole method makes the previously isolated special case of boolean getters bleed much further. Thus, I'd prefer to leave it as is.

Comment on lines 58 to 63
# If it's a boolean create an alias for it and remove question mark
if option_name.end_with?('?')
scope.send(:define_method, "#{option_name.chop!}?") do
option_name = option_name.chop
scope.send(:define_method, "#{option_name}?") do
send(option_name)
end
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.

2 participants