Jump to ratings and reviews
Rate this book
Rate this book
Praise for Design Patterns in Ruby

" Design Patterns in Ruby documents smart ways to resolve many problems that Ruby developers commonly encounter. Russ Olsen has done a great job of selecting classic patterns and augmenting these with newer patterns that have special relevance for Ruby. He clearly explains each idea, making a wealth of experience available to Ruby developers for their own daily work."

--Steve Metsker, Managing Consultant with Dominion Digital, Inc.

"This book provides a great demonstration of the key 'Gang of Four' design patterns without resorting to overly technical explanations. Written in a precise, yet almost informal style, this book covers enough ground that even those without prior exposure to design patterns will soon feel confident applying them using Ruby. Olsen has done a great job to make a book about a classically 'dry' subject into such an engaging and even occasionally humorous read."

--Peter Cooper

"This book renewed my interest in understanding patterns after a decade of good intentions. Russ picked the most useful patterns for Ruby and introduced them in a straightforward and logical manner, going beyond the GoF's patterns. This book has improved my use of Ruby, and encouraged me to blow off the dust covering the GoF book."

--Mike Stok

" Design Patterns in Ruby is a great way for programmers from statically typed objectoriented languages to learn how design patterns appear in a more dynamic, flexible language like Ruby."

--Rob Sanheim, Ruby Ninja, Relevance

Most design pattern books are based on C++ and Java. But Ruby is different--and the language's unique qualities make design patterns easier to implement and use. In this book, Russ Olsen demonstrates how to combine Ruby's power and elegance with patterns, and write more sophisticated, effective software with far fewer lines of code.

After reviewing the history, concepts, and goals of design patterns, Olsen offers a quick tour of the Ruby language--enough to allow any experienced software developer to immediately utilize patterns with Ruby. The book especially calls attention to Ruby features that simplify the use of patterns, including dynamic typing, code closures, and "mixins" for easier code reuse.

Fourteen of the classic "Gang of Four" patterns are considered from the Ruby point of view, explaining what problems each pattern solves, discussing whether traditional implementations make sense in the Ruby environment, and introducing Ruby-specific improvements. You'll discover opportunities to implement patterns in just one or two lines of code, instead of the endlessly repeated boilerplate that conventional languages often require.

Design Patterns in Ruby also identifies innovative new patterns that have emerged from the Ruby community. These include ways to create custom objects with metaprogramming, as well as the ambitious Rails-based "Convention Over Configuration" pattern, designed to help integrate entire applications and frameworks.

Engaging, practical, and accessible, Design Patterns in Ruby will help you build better software while making your Ruby programming experience more rewarding.

384 pages, Hardcover

First published December 10, 2007

Loading interface...
Loading interface...

About the author

Russ Olsen

5 books77 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
303 (38%)
4 stars
337 (42%)
3 stars
131 (16%)
2 stars
17 (2%)
1 star
7 (<1%)
Displaying 1 - 30 of 49 reviews
4 reviews
August 15, 2009
Good but overly wordy book of design patterns in ruby. Ruby implementations of design patterns are definitely terse which is exciting and the patterns are very useful. There were several cases where I could think of simpler or alternate implementations than the ones given (e.g. composite).

There was a little too much cruft around failed versions of the design pattern which obscured skimming for successful implementations when using the book as a reference. In my opinion book could be condensed by about 100 pages and be restructured into a more usable reference. That said, it's a very valuable book to have written in the Ruby language rather than interpreting other references in C++ (the GoF Design patterns book), Java (Martin Fowlers works), or Small Talk (Kent Beck's earlier works).

I'm giving it 4 stars because of it's relevence to Ruby programming. But if there were a lot of alternatives in the Ruby language I might give it a 3 because it's a little crufty. An example of a non-crufty book that I think rocks is the O'Reilly book Algorithms in A Nutshell which is frickin amazing.
Profile Image for Angelos.
10 reviews
August 14, 2017
A solid book on Design Patterns that serves as a nice introduction to the topic.

Sadly, it has some serious flaws that prevent it from being great. In order of decreasing importance:

- There is a vast amount of typographical mistakes (typos) in the text and formatting inconsistencies in the code samples. This makes reading the book distracting if you are prone to noticing them.
- I found the style of writing to be somewhat wordy. I think it would have served the book better to be terser and shorter (would be better as a reference as well). There are whole paragraphs devoted to concepts or things that could have been stated clearly and directly in a few lines.
- A few examples applied to patterns feel a bit convoluted and unfit. The case of the Factory pattern comes to mind.
- The coding style used in the code samples is often non-idiomatic Ruby, maybe in an attempt to make it easier for non-Ruby programmers to grasp? This, however, alienates readers who know Ruby and I think it's a bad trade-off. E.g. wrapping if statements with parentheses or using unnecessary returns in methods.
- I feel it's not the purpose of a book like this to teach someone Ruby (you can't do it in 40 pages, so you might as well not do it at all). If that section was removed, the book would have been at least 40 pages shorter. There are also some smaller sections throughout the book that teach about Ruby as well (like method_missing).
- The book was published in 2007, so it's 10 years old. Although still highly relevant in terms of the Design Patterns it presents, some code no longer works in the latest versions of Ruby.

That said, I feel like I've gained enough by reading this book and would highly recommended it to anyone insterested in a good introduction to Design Patterns, especially if they know Ruby.

I'd give it 3.5 stars, but since there are no half stars, I feel it's closer to a 4, so here it goes.
404 reviews65 followers
January 12, 2012
This was such a fun and useful book! It picks 14 out of the 23 commonly known design patterns in programming, and demonstrates how they can be uniquely expressed in Ruby. Then it adds three more that are commonly used in Ruby code.

This book is so well-written, with very understandable explanations and code, and plenty of fun quips to keep it light, but also very concise. This book weighs in at 340 pages, which is tiny for a programming book. I also like that this author didn't take the easy way out by targeting only advanced programmers. It would have been unnecessary, as Ruby is so easy that the basics can be explained in a few pages, and the rest filled out as he goes along. As a result, this is actually a great book to quickly learn both Ruby and design patterns in one fell swoop.
October 18, 2022
It's a good book but it's also overwhelming because of the exemples the author used throught the book, some concepts would be more easy to understand if he used some simple or understandable exemples.
I read like 90% of it but dropped in the Part III because i think it wans't worth it. Maybe in the future i'll pick up this book to read again and finish 100%.
Profile Image for Eric Li.
81 reviews
December 14, 2020
One of those programming books that you can read like a collection of blog post rather than a text book.
As a newbie for Rails, I find the "design pattern in wild" section very helpful for learning RoR by example.
Profile Image for Matt.
83 reviews2 followers
December 20, 2017
Pretty good overview of the Gang of Four’s original Design Patterns, but viewed through the lens of Ruby instead of Java.
Profile Image for Bill.
216 reviews75 followers
July 21, 2018
Focuses on the most common of the Gang of Four patterns in one of the most elegant languages. Highly recommended for Ruby developers.
Profile Image for Jason.
348 reviews14 followers
August 3, 2019
Great writer and it was really helpful for me to see examples in a language I'm familiar with. Learned a ton and will be revisiting as a reference for sure.
7 reviews
January 15, 2021
Great book that builds up your understanding of design patterns and relates them to real world challenges of software design.
March 3, 2023

Best material about design patterns applied to Ruby, great examples and definitely much more light weight than reading the Gang of 4.
Profile Image for James Stewart.
38 reviews6 followers
March 28, 2008
For many the idea of bringing design patterns to ruby is a terrifying one. Having taken refuge from over-engineered java projects (or for that matter, attempts to apply java engineering approaches to a somewhat dynamic language like PHP) the baggage that often goes along with design patterns isn’t what a recent convert is looking for. But as I mentioned in my last review of a design patterns volume, and series editor Obie Fernandez highlights in his foreword, design patterns don’t have to be used that way and maintain merit when used as a source of collective experience and shared language.

Russ Olsen’s book does a good job of stepping through the key patterns from the Gang of Four’s initial offering, showing how they can be applied to and simplified with Ruby, introducing along the way various uses of blocks, mix-ins, and other powerful features of the language that may be unfamiliar to newcomers. Each chapter highlights how the pattern can be used or abused, sounding a note of caution to dissuade unthinking embrace of every pattern between its covers. It’s clearly written with a nice balance of code to prose.

Towards the end of the book a couple of “new” patterns are offered, particularly “internal DSLs”, “meta-programming” and “convention over configuration.” Opinions differ over whether of those can really be considered patterns in the general sense of the term. Certainly those concepts are examples of a community gradually refining its approaches to common problems, but at least two of them are considerably more conceptual and abstract than most of the other patterns in the book. Perhaps the best way to understand them is as giving an insight into the working patterns of the ruby community approaches problems, and pointers to topics worthy of more exploration.

That usage of the final few chapters gives some indication of the probable audience for this book. It seems best suited to those who have dabbled with ruby but don’t yet have much experience. A general sense of syntax is all you’ll need going in, but you’ll come away with a much stronger sense of the language’s features than that. Similarly it’ll work well for those with a general sense of the major patterns but who could do with a refresher, maybe while transitioning from java or other “enterprisey” development to ruby.

While it won’t have the same general appeal of other titles in the series like The Ruby Way and The Rails Way, this is a handy volume in a series that is making strong contributions to the ruby book market.

Disclaimer: I was sent a copy of this book for review by the publisher. There were a few pages missing due to a printing defect so I wan’t able to read parts of chapters 13 or 14.
6 reviews3 followers
August 3, 2013
Overall, interesting concepts here.
But this book wasn't was i was looking for regarding Design Patterns applied to Ruby.
Perhaps the book is a little outdated by now.
There is an entire chapter dedicated to Getting started with Ruby and i wonder why wasting pages on beginner stuff on a Design Patterns book..

More critics:

# Lacks Ruby idioms, e.g. page 181
@subject || (@subject = BankAccount.new(@starting_balance))
# Doesn't embrace Ruby syntactic sugar like the memoized accessor ||=
@subject ||= BankAccount.new(@starting_balance)

# You see strange code like
def withdraw(amount)
s = subject
return s.withdraw(amount)
# Instead of simply
def withdraw(amount)
# Or maybe
delegate :withdraw, to: subject
# Using 'forwardable'
def_delegators :subject, :withdraw

# Strange example of a Java style ArrayIterator class instead of directly jumping into how to mixin Enumerable module.

# More unusual code:
if Etc.getlogin != @owner_name
raise "Illegal access: #{Etc.getlogin} cannot access account."
# Instead of using `unless`
unless Etc.getlogin == @owner_name
raise "Illegal access: #{Etc.getlogin} cannot access account."

# In page 258 an explicit arguments super() is used while that can be done by default in Ruby by simply using super with no arguments
def method_missing(name, *args)
... # no modifications to name nor *args here ...
return super(name, *args) unless ...
Profile Image for Chris Wood.
42 reviews4 followers
March 29, 2014
The original GoF book on the subject of design patterns over two decades ago provided a robust set of solutions aimed at creating modular, maintainable code in primarily statically typed languages. While these patterns port relatively seamlessly into dynamic languages, they fail to fully harness the expressive and concise power of a dynamic language such as Ruby.

"Design Patterns in Ruby" sits in the middle between an introduction to the ruby language (and dynamic typing in general) and an introduction to design patterns. For experienced ruby developers, the patterns offer clearly expressed methods for code reusability. For those proficient in design patterns for static languages, this book shows how to think of the patterns in ruby.

My general complaint with this book is that it did not adequately explore techniques for building the design patterns in Ruby with metaprogramming. Rather than treating metaprogramming, which is such a vital component to professional ruby software development, in a final closing chapter, I would have preferred more treatment throughout the course of the patterns.

Overall, this is a great read for those looking to get into ruby and design patterns.
5 reviews
May 20, 2014
3.5 stars. The book provides a good overview of the design patterns using Ruby as its context. He makes the content accessible to readers with little/no experience with Ruby. The author maintained a conversational tone throughout the book, which is necessary to avoid it being boring. In several chapters the author missed opportunities to explain Ruby features that would assist in implementing the pattern. For example, (Ch. 7) calling the #each method without a block returns an external iterator and (Ch. 10) extending the BasicObject class allows a proxy class to avoid inheriting implementations for the multitude of Object methods.

In many locations, the author does not use Ruby in an idiomatic way (e.g., among many, using "eval" on strings to add methods instead of using "define_method"), and many of his examples are not very enlightening as to how the pattern would really be used. (And his meta-programming examples were particularly bad.) I got the impression that the author hadn't fully adjusted to effectively utilizing dynamically typed languages.

Overall, it's a book I'd recommend to someone new to both Ruby and patterns. But, I suspect the book "Practical Object-Oriented Design in Ruby: An Agile Primer" by Sandi Metz might be a better choice.
Profile Image for Ken-ichi.
593 reviews555 followers
September 9, 2008
Having recently taken a course on design patterns, I was eager to start applying them in my work. Most of the examples out there are very Java-oriented, and I was constantly wondering whether my implementations were "rubyish" enough. This book is an expensive but well-written and well-organized response to that problem. Olsen does a great job describing each pattern, how it's been traditionally described, how it changes in Ruby, and how it's actually been applied in the wild.

One of my favorite pieces of advice is his meta-pattern "You Ain't Gonna Need It." Basically, if you don't need a piece of functionality right now, don't code it. Don't try to predict what might be useful down the line, because you'll probably be wrong, and given the fluid, iterative nature of software development and maintenance, you'll probably end up re-writing it anyway. I tend to over-think things, so I need to keep this in mind.
Profile Image for Michael.
Author 7 books593 followers
June 25, 2010
As a Java programmer finally checking out Ruby I must say that it felt like this book was written for me. I don't mean for someone "like" me but ME. I've studied the GoF patterns extensively and have always been left wanting (leading to my explorations into more expressive languages). However, Mr. Olsen seems to understand this exquisite yearning and addresses it head on. Each section presents a laser focus on the misshapen GoF pattern and systematically slices off the knobby bits until only the pure Ruby gem is left for us to marvel on. Additionally, I enjoy intelligence mixed with humor and "Design Patterns in Ruby" did not fail to deliver on both counts. Given 1,000,000 years I can't imagine that I nor anyone else could write a better Ruby book.
Profile Image for Mani .
61 reviews22 followers
January 15, 2016
I was looking for a fast way to port the design patterns that I have learned over the last decade into Ruby so that I could feel proficient quickly. This book does it!

The author gets into the differences in architecture patterns as you would build them in Java and how and why you would do so differently in Ruby.

You also get a good dose of Domain Specific Languages and Ruby Metaprogramming.

I phased out a bit towards the end of this book. Shit was stretching my noggin the light fantastic. I will come back to the last few chapters when I am a more advanced Ruby dev though- maybe next year, maybe in 5 years.

I enjoyed the author's tone and his dry sense of humor. I moved right on to reading his second book, Eloquent Ruby.
Profile Image for Craig.
47 reviews3 followers
July 17, 2012
I've only referred to the GoF Pattern book a couple of times in the years when I had something I needed to do and just needed some ideas. I've been wanting to learn Ruby and Ruby on Rails for years, ever since seeing David Heinemeier Hansson do a presentation at an OSCON I attended. This book was a recommendation and I was very impressed with how Russ not only presented the pattern but described how to implement with Ruby that the most basic Ruby programmer could understand. I was also very impressed with his knowledge of the underpinnings of Ruby and other languages. It was a long book with lots of theories, but flowed much better than any other concept book I've read.
Profile Image for Tamara.
110 reviews24 followers
November 10, 2013
Only a wee bit dated, but still a true Tour de Force showing how the well-know Design Patterns from the Gang of Four are well implemented in Ruby. Each chapter covers a particular pattern, but more importantly, discusses when to use them, and when to avoid them. Russ's writing style is high on explanation by demonstration (show me, don't tell me) but with good discussion about what is going on as well. The back part of the book discusses some patterns that have emerged in the Ruby world, especially with Rails. I highly recommend this book to all Rubyists, and those learning how to write computer programs in general.
Profile Image for Willian Molinari.
Author 2 books117 followers
April 18, 2021
Read this one ~2013 and liked it a lot. I was interested in reading about design patterns but didn't want to go through the GoF book and read about many patterns that were not a reality for me a the time. Reading this book was great to go through the most common patterns without having to read the ones that make more sense on certain languages.

It was great to see that Ruby has great support for some patterns already. The best exemple to cite here is the Singleton pattern that is already implemented in the Ruby standard library.
Profile Image for Alex.
104 reviews15 followers
January 18, 2010
Great book. I'd never read about design patterns, so being introduced to them with a Ruby perspective was very valuable. It's a valuable introduction and store of information to keep in the back of my mind for the problems I'll encounter. (Like one I already have -- I'm about to use the Composite pattern for a personal project.) Definitely recommended for any Ruby developer.
Profile Image for Harri Kauhanen.
26 reviews5 followers
January 7, 2012
Somewhat weird concept being a Ruby tutorial and patterns reference at the same time. Author's writing style is already showing signs of mastery... And master he becomes in his next book "Eloquent Ruby". Time for just one Ruby book? Pick the latter one. Definitely want a classical GoF point of view on things? This is not a bad book.
Profile Image for Chris Adams.
17 reviews26 followers
March 31, 2014
If you've learned to code with ruby as a first language, this book helps you understand why design patterns are so prominent in other languages, but it also helps explain why Ruby's dynamic nature lets you get by with the language's own features before needing to reach for the Gang of Four's techniques.
Profile Image for Ben Rand.
322 reviews4 followers
April 21, 2015
A good book on Design Patterns. I kind of like revisiting this topic frequently as I learn more each time I do. It's interesting to see the same patterns applied in different languages as they all bring their own nuances to it. Ruby is especially unique this way as its dynamic nature enables you to do things that are very difficult to pull off in more traditional languages (Java, C#).
Profile Image for David Medinets.
Author 8 books1 follower
March 18, 2015
Russ Olsen has produced a handsome book full of basic design patterns. The second chapter provides a quick introduction to the Ruby language and then Russ hand-picks patterns that are relevant to Ruby programming.
Displaying 1 - 30 of 49 reviews

Can't find what you're looking for?

Get help and learn more about the design.