Skip to content
I'll Be Back
end
Lessons
How it works
Search lessons
/
@illbebackend
Lessons
/
Principles
/
DRY: one rule, one place
Principles · Ruby
DRY: one rule, one place
Change a business rule once and have every feature pick it up.
13 steps
4 chapters
~4 min at 1.25×
#duplication
#constants
#single source of truth
Language
Java
Kotlin
C#
C++
Python
Ruby
PHP
TypeScript
JavaScript
Go
Rust
Swift
The lesson plays right here. Pause anywhere, step back, or jump to a step below.
Watch the Ruby video on YouTube
Code on GitHub
Every step
Problem
Steps 1–3
01
Three features, one rule
Before
02
Members ship free from 25
Code smell
03
Undo, then give it a home
Plan
Refactor
Steps 4–10
04
Name the limit
Extract Constant
05
Name the fee
Extract Constant
06
Name the check
Extract Function
07
The banner asks too
Replace Inline Code with Function Call
08
The email asks too
Replace Inline Code with Function Call
09
Name the gap
Extract Function
10
Hide the limit
Encapsulate Variable
Payoff
Step 11
11
Members, in one module
Payoff
Recap
Steps 12–13
12
Where we started, where we ended
Before / after
13
When to reach for it
Takeaways