Chapter 1. A Refactoring Example
Rather than start with a lot of explanation, we’ll begin with a quick example of refactoring to show how you can identify problems in code and systematically clean them up. We’ll work “at speed” so you can get the feel of a real session. In later chapters, we’ll touch on theory, provide deeper dives into problems and how you fix them, and explore moderately large examples that you can practice on.
Sparkline Script
Let’s take a look at a little Ruby script Kevin wrote a while back. The script generates a sparkline (a small graph used to display trends, without detail) and does it by generating an SVG document to describe the graphic. (See Figure 1.1.)
The original script was written ...
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.