Chapter 3. Refactoring Step by Step

It’s time we looked in detail at the mechanics of refactoring. In this chapter we’ll work through the steps involved in Hide Delegate; but first we need to review our tools.

The Refactoring Environment

Refactoring can be done on any code at any time, but it’s easier and safer with a supportive environment. Be sure to have most of the following tools ready at your side before you begin refactoring:

Team or Partner: For nontrivial decisions about code, it’s helpful to have more than one person considering the problem. A team can often generate ideas better than one person alone: Different people have different experiences and different exposure to different parts of the system.

Tests: Even though refactorings ...

Get Refactoring in Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.