---
title: Centralize Constants
impact: MEDIUM
impactDescription: improves maintainability and avoids magic numbers
tags: constants, maintainability, quality
---

## Centralize Constants

Avoid hardcoding magic strings and numbers throughout your logic. Define them as constants at the top of the class or in a specific module.

**Incorrect (magic values):**

```ruby
class User < ApplicationRecord
  def premium?
    self.score > 1000 # What is 1000?
  end
end
```

**Correct (constants):**

```ruby
class User < ApplicationRecord
  PREMIUM_THRESHOLD = 1000

  def premium?
    score > PREMIUM_THRESHOLD
  end
end
```

**Tools:** RuboCop
---
