Design Patterns In Ruby

Design Patterns In Ruby

A few years ago I didn’t know that design patterns existed when writing software. It was only when I started tinkering with Ruby, because of Rails, that I heard about a book called Design Patterns: Elements of Reusable Object-Oriented Software written by the mythical sounding “Gang of Four”.

Whenever I’ve been writing Ruby code in the past I’ve always had the nagging feeling that I’m doing it wrong. There is obviously more than one way to tackle a problem but I never know if I’ve taken the correct path. Countless blog posts have been devoted taking a class, or a method, and re-factoring it, making it leaner and cleaner. I guess the only way to learn is to write it so that it works, then go back to it over time and re-factor it. Surprisingly, after reading this book, that’s what I’m doing now to one of my little Ruby projects.

The book takes 14 of the classic patterns and considers them from the point of view of Ruby code. It covers the background and basic Ruby concepts and idioms in the first part before launching into patterns. The third part discusses patterns for Ruby and looks into the Rails code.

For a book that is so heavily code related it is surprisingly easy to read away from the keyboard. But to really understand how the code works you would need to run and tweak it to see what makes it tick. That’s what I intend to do next.

A book to always keep near you for those times when you feel that someone must have dealt with this coding problem before.