---
title: Use frozen_string_literal: true
impact: LOW
impactDescription: Improve memory efficiency and prepare for Ruby 4.0 string immutability.
tags: ruby, performance, memory, preparation
---

## Use frozen_string_literal: true

Improve memory efficiency and prepare for Ruby 4.0 string immutability. Add `# frozen_string_literal: true` magic comment at the top of every Ruby file.

**Incorrect:**

```ruby
class MyClass
  DEFAULT_STATUS = "pending" # New string object created every time
end
```

**Correct:**

```ruby
# frozen_string_literal: true
class MyClass
  DEFAULT_STATUS = "pending" # String object is frozen and reused
end
```

**Tools:** RuboCop (`Style/FrozenStringLiteralComment`)
