FrozenError: can't modify frozen String Ruby / Rails Origin: Application & API OSI layer 7 · Application Last updated 5 Nov 2026

Ruby: FrozenError: can't modify frozen String: "abc"

You tried to change an object that's frozen — string literals under # frozen_string_literal: true, constants, symbols or frozen hashes.

Exact message you may see FrozenError: can't modify frozen String: "abc"FrozenError (can't modify frozen String)can't modify frozen Hashcan't modify frozen ArrayFrozenError: can't modify frozen object
Seen on: Ruby

Meaning

Use non-mutating methods (+, dup, String.new, gsub instead of gsub!), or unfreeze with +"text"/dup. Rails freezes some options/params; copy with dup before changing. Ruby 3.4 warns about mutating string literals.

Common causes

  • # frozen_string_literal: true with << or gsub!
  • Modifying a constant (CONST << x)
  • Mutating a frozen hash (params.freeze)
  • Ruby 3.4 chilled strings
  • Gems returning frozen objects

⚡ Quick fix

  1. s = +"text" or s = "text".dup then mutate
  2. Prefer s += "x"
  3. Use String.new for buffers

Detailed fix by platform

Ruby

  1. buffer = String.new; buffer << "a"

How to diagnose

  1. Object — Frozen why?
  2. Method — Mutating bang?
  3. Fix — dup?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

ArgumentError: missing keyword / unknown keyword — Ruby: ArgumentError: missing keyword: :name / unknown keyword: :nmae (Ruby / Rails)ArgumentError: missin…ArgumentError: wrong number of arguments (given 1, expected 2) — Ruby: ArgumentError: wrong number of arguments (given 1, expected 2..3) (Ruby / Rails)ArgumentError: wrong …Bundler could not find compatible versions for gem — Bundler: Bundler could not find compatible versions for gem "activesupport": In Gemfile: rails (= 7.1.0) depends on activesupport (= 7.1.0) (Ruby / Rails)Bundler could not fin…Bundler: Could not find gem in locally installed gems — Bundler: Could not find gem 'rails (~> 7.1)' in locally installed gems / Could not find rails-7.1.0 in any of the gem sources listed in your Gemfile (Ruby / Rails)Bundler: Could not fi…FactoryBot::DuplicateDefinitionError: Factory already registered — FactoryBot: FactoryBot::DuplicateDefinitionError: Factory already registered: user (Ruby / Rails)FactoryBot::Duplicate…NameError: undefined local variable or method — Ruby: NameError: undefined local variable or method 'x' for main:Object (Ruby / Rails)NameError: undefined …TypeError: no implicit conversion of nil into String — Ruby: TypeError: no implicit conversion of nil into String (Ruby / Rails)TypeError: no implici…FrozenErr…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.