Mutable string
Strings should be immutable by default in Ruby 4.0. The comment # frozen_string_literal: true
will no longer be useful. Starting with Ruby 3.4, a warning will be present (if enabled: -W
) when a string is modified.
This applies only to literal strings.
To have a mutable string, use # frozen_string_literal: false
for all strings in a file, or use the +@
method, which creates a copy if the string is immutable.
Link to Ruby documentation for String#+@
and the one of the feature
.