Skip to content

Ruby 3.4.10 address frozen string warning - #1

Open
tsoto111 wants to merge 3 commits into
amcaplan:masterfrom
tsoto111:ruby-3.4.10-address-frozen-string-warning
Open

Ruby 3.4.10 address frozen string warning#1
tsoto111 wants to merge 3 commits into
amcaplan:masterfrom
tsoto111:ruby-3.4.10-address-frozen-string-warning

Conversation

@tsoto111

@tsoto111 tsoto111 commented Sep 8, 2026

Copy link
Copy Markdown

Problem

Ruby 3.4.10 has started adding a new warning polluting our application logs.

warning: string returned by *.to_s will be frozen in the future

NOTE: The * in the example above represents a wild card value as this error is being thrown for any variable that was being converted to a string using the to_s method.

This is specifically being raised by mname.chomp!('=') via lib/persistent_open_struct.rb as it is mutating the original string saved to mname. This will raise an error in the future when mname variable string is frozen.

Solution

Logic was refactored to not modify the original variable of mname in the conditional statement. Instead, we will perform a check of mname.end_with?('=').

Then, in the original usage of the modified variable we will now call chomp without the ! to return a dup string instead of the original modified string. This refactor addresses the warnings of strings being frozen in future versions of ruby.

Additional Cleanup

  1. Remove pinned bundler version - In order to get the test suite to run I removed the pinned version of bundler from the gemspec which allows everyone to use the version of bundler installed on their machine.
  2. Update Rack - Tests could not run because the version of rake was too old. As a result, I updated it to a newer version that successfully ran tests.
  3. Deprecate assert_equal nil - In one of the mini-tests a warning was raised because the gem used assert_equal to check nil. To address this warning usage of assert_nil was added instead.

Tests after updates

persistent_open_struct % bundle exec rake test
~/.rbenv/versions/3.4.10/bin/ruby -w -I"lib:test" ~/.rbenv/versions/3.4.10/lib/ruby/gems/3.4.0/gems/rake-13.4.2/lib/rake/rake_test_loader.rb "test/test_helper.rb" "test/test_persistent_open_struct.rb" -v
Run options: -v --seed 34943

# Running:

PersistentOpenStructTest#test_method_missing = 0.00 s = .
PersistentOpenStructTest#test_eql_and_hash = 0.00 s = .
PersistentOpenStructTest#test_method_segregation = 0.00 s = .
PersistentOpenStructTest#test_getter = 0.00 s = .
PersistentOpenStructTest#test_each_pair = 0.00 s = .
PersistentOpenStructTest#test_delete_field = 0.00 s = .
PersistentOpenStructTest#test_inspect = 0.00 s = .
PersistentOpenStructTest#test_frozen = 0.00 s = .
PersistentOpenStructTest#test_equality = 0.00 s = .
PersistentOpenStructTest#test_equality_of_subclasses = 0.00 s = .
PersistentOpenStructTest#test_to_h = 0.00 s = .
PersistentOpenStructTest#test_initialize = 0.00 s = .
PersistentOpenStructTest#test_setter = 0.00 s = .
PersistentOpenStructTest#test_method_reuse = 0.00 s = .

Finished in 0.000935s, 14973.2617 runs/s, 62032.0844 assertions/s.

14 runs, 58 assertions, 0 failures, 0 errors, 0 skips

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.

1 participant