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

**Code:** `FrozenError: can't modify frozen String` · **Category:** Ruby / Rails · **Seen on:** Ruby

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/ruby/frozenerror-cant-modify-frozen-string)
