0032 Frozen_string

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.

0032-frozen_string_1.png

This applies only to literal strings.

0032-frozen_string_2.png

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.

0032-frozen_string_3.png

Link to Ruby documentation for String#+@ and the one of the feature.