Want to see the full-length video right now for free?

Sign In with GitHub for Free Access


In this episode, Joe and Ben discuss a fairly advanced example of refactoring.

You'll dive into the good, the bad, and the ugly of code before and after being rewritten. The new code uses a number of design patterns, including the Builder pattern, the Chain of Responsibility pattern, the Null Object pattern, and the Decorator pattern. It also combines object-oriented object composition with functional style recursion using inject.

We briefly discuss the benefits of using immutable objects to avoid confusing state and identity.

We also wrote a blog post about this refactoring if you'd like to follow along in a textual format. You can see the Full example on GitHub and follow along as you watch.

If you'd like to see more examples of this type of refactoring, check out Ruby Science.