| |
| |
Foreword | |
| |
| |
Preface | |
| |
| |
Acknowledgments | |
| |
| |
About the Author | |
| |
| |
| |
Patterns and Ruby | |
| |
| |
| |
Building Better Programs with Patterns | |
| |
| |
The Gang of Four | |
| |
| |
Patterns for Patterns | |
| |
| |
Separate Out the Things That Change from Those That Stay the Same | |
| |
| |
Program to an Interface, Not an Implementation | |
| |
| |
Prefer Composition over Inheritance | |
| |
| |
Delegate, Delegate, Delegate | |
| |
| |
You Ain't Gonna Need It | |
| |
| |
Fourteen Out of Twenty-Thre | |
| |
| |
Patterns in Ruby? | |
| |
| |
| |
Getting Started with Ruby | |
| |
| |
Interactive Ruby | |
| |
| |
Saying Hello World | |
| |
| |
Variables | |
| |
| |
Fixnums and Bignums | |
| |
| |
Floats | |
| |
| |
There Are No Primitives Here | |
| |
| |
But Sometimes There Is No Object | |
| |
| |
Truth, Lies, and nil | |
| |
| |
Decisions, Decisions | |
| |
| |
Loops | |
| |
| |
More about Strings | |
| |
| |
Symbols | |
| |
| |
Arrays | |
| |
| |
Hashes | |
| |
| |
Regular Expressions | |
| |
| |
A Class of Your Own | |
| |
| |
Getting at the Instance Variables | |
| |
| |
An Object Asks: Who Am I? | |
| |
| |
Inheritance, Subclasses, and Superclasses | |
| |
| |
Argument Options | |
| |
| |
Modules | |
| |
| |
Exceptions | |
| |
| |
Threads | |
| |
| |
Managing Separate Source Files | |
| |
| |
Wrapping Up | |
| |
| |
| |
Patterns in Ruby | |
| |
| |
| |
Varying the Algorithm with the Template Method | |
| |
| |
Keeping Up with What Life Throws at You | |
| |
| |
Separate the Things That Stay the Same | |
| |
| |
Discovering the Template Method Pattern | |
| |
| |
Hook Methods | |
| |
| |
But Where Are All the Declarations? | |
| |
| |
Types, Safety, and Flexibility | |
| |
| |
Unit Tests Are Not Optional | |
| |
| |
Using and Abusing the Template Method Pattern | |
| |
| |
Templates in the Wild | |
| |
| |
Wrapping Up | |
| |
| |
| |
Replacing the Algorithm with the Strategy | |
| |
| |
Delegate, Delegate, and Delegate Again | |
| |
| |
Sharing Data between the Context and the Strategy | |
| |
| |
Duck Typing Yet Again | |
| |
| |
Procs and Blocks | |
| |
| |
Quick-and-Dirty Strategies | |
| |
| |
Using and Abusing the Strategy Pattern | |
| |
| |
The Strategy Pattern in the Wild | |
| |
| |
Wrapping Up | |
| |
| |
| |
Keeping Up with the Times with the Observer | |
| |
| |
Staying Informed | |
| |
| |
A Better Way to Stay Informed | |
| |
| |
Factoring Out the Observable Support | |
| |
| |
Code Blocks as Observers | |
| |
| |
Variations on the Observer Pattern | |
| |
| |
Using and Abusing the Observer Pattern | |
| |
| |
Observers in the Wild | |
| |
| |
Wrapping Up | |
| |
| |
| |
Assembling the Whole from the Parts with the Composite | |
| |
| |
The Whole and the Parts | |
| |
| |
Creating Composites | |
| |
| |
Sprucing Up the Composite with Operators | |
| |
| |
An Array as a Composite? | |
| |
| |
An Inconvenient Difference | |
| |
| |
Pointers This Way and That | |
| |
| |
Using and Abusing the Composite Pattern | |
| |
| |
Composites in the Wild | |
| |
| |
Wrapping Up | |
| |
| |
| |
Reaching into a Collection with the Iterator | |
| |
| |
External Iterators | |
| |
| |
Internal Iterators | |
| |
| |
Internal Iterators versus External Iterators | |
| |
| |
The Inimitable Enumerable | |
| |
| |
Using and Abusing the Iterator Pattern | |
| |
| |
Iterators in the Wild | |
| |
| |
Wrapping Up | |
| |
| |
| |
Getting Things Done with Commands | |
| |
| |
An Explosion of Subclasses | |
| |
| |
An Easier Way | |
| |
| |
Code Blocks as Commands | |
| |
| |
Commands That Record | |
| |
| |
Being Undone by a Command | |
| |
| |
Queuing Up Commands | |
| |
| |
Using and Abusing the Command Pattern | |
| |
| |
The Command Pattern in the Wild | |
| |
| |
ActiveRecord Migrations | |
| |
| |
Madeleine | |
| |
| |
Wrapping Up | |
| |
| |
| |
Filling in the Gaps with the Adapter | |
| |
| |
Software Adapters | |
| |
| |
The Near Misses | |
| |
| |
An Adaptive Alternative? | |
| |
| |
Modifying a Single Instance | |
| |
| |
Adapt or Modify? | |
| |
| |
Using and Abusing the Adapter Pattern | |
| |
| |
Adapters in the Wild | |
| |
| |
Wrapping Up | |
| |
| |
| |
Getting in Front of Your Object with a Proxy | |
| |
| |
Proxies to the Rescue | |
| |
| |
The Protecti | |