Appendix A. Answers to Selected Questions

We’ve included answers to some of the problems here. Where we’ve omitted answers, it’s usually because we’ve asked you to work in your own code or because we want you to consider an issue on your own.

The Refactoring Cycle

Exercise 2.1: Simple Design

A.

  1. Passes all tests. “If it doesn’t have to work, I can give it to you right now.”
  2. Communicates. This makes an appeal to our intuition about future readers of our code (including ourselves).
  3. No duplication. Duplicate code is asking for trouble; it’s too vulnerable to changes in one place but not the other.
  4. Fewest classes and methods. All things being equal, we prefer smaller code.

B.

The bottom line is that there’s an appeal to the reader’s ability ...

Get Refactoring in Ruby now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.