Patterns for Joyful Coding

Confident Ruby is, first and foremost, a book about joy. It’s about the joy I found when I first discovered how elegantly and succinctly I could state problems in Ruby code. It’s about the joy I gradually lost as the “real world” snuck in and cluttered my code with distracting edge case scenarios, error handling, and checks for nil. And it’s about how I came to recapture that joy, by employing small patterns and stylistic choices to make each method tell a coherent story.

The structure of the book is that of a patterns catalog. But these are not large, heavy-weight architectural patterns. These patterns are small, most of them taking place at the level of an individual method or even a single line of code. They are related by a single organizing principle: removing the uncertainty that leads to code constantly second-guessing itself; and replacing it with a confident, clear focus on the task at hand.

In these pages you’ll find:

  • 32 patterns for writing confident code.
  • How to avoid the “MacGyver method”—a step-by-step guide to thinking about methods in terms of the story they tell rather than the building blocks that happen to be lying around.
  • The most comprehensive coverage anywhere of Ruby’s conversion methods and protocols. You’ll learn not just how to convert built-in objects from one to another, and when to use #to_a vs. #to_ary vs. Array(); but also how to adopt Ruby’s conversion conventions to make your own objects powerfully extensible.
  • How to streamline your code and eliminate repetitive conditionals with the Special Case and Null Object patterns… and how to avoid the gotchas that can come with naive implementations of these patterns.
  • Simple habits to eliminate the dreaded “NoMethodError for NilClass” exception.
  • How to make your methods more flexible by passing in behavior instead of data.
  • How to helpfully deliver results from your methods when the possible outcomes are more nuanced than “success” or “failure”.
  • An applied demonstration of refactoring two Open-Source Ruby projects using patterns from the book.
  • And much, much more… nearly 300 pages of material and hundreds of code listings.
"Not only did Confident Ruby make me a better developer, it made complicated code fun instead of intimidating." Kevin Sjöberg
"The best book you can read if you want to recapture Ruby's fun spirit again."Matt Rogers
"After over 30 years developing software for a living… Confident Ruby showed me ways I could design and write better code"Jeff Dickey

The Talk

Curious about the kind of material you'll find in this book? Here's a video of the talk that inspired it.

Want a taste of the book?
Download a PDF sample, containing the introduction and three patterns.

Download Sample PDF

$55

Buy Now

Gold Label Edition

  • Confident Ruby in PDF, EPUB, and Kindle formats
  • The Confident Ruby companion screencast more…Watch over my shoulder as I apply concepts and patterns from the book to the Discourse codebase.
  • Much Ado About Naught: An Adventure in Metaprogramming more…This bonus ebook follows the step-by-step, test-driven development of the “Naught” gem for constructing Null Object classes. It covers most of the metaprogramming techniques, tricks, and gotchas I’ve picked up over the years, and comes complete with whimsical Paintbrush illustrations by Lauren Shepard! (aka my mom)

$45

Buy Now

Black Label Edition

  • Confident Ruby in PDF, EPUB, and Kindle formats
  • The Confident Ruby companion screencast more…Watch over my shoulder as I apply concepts and patterns from the book to the Discourse codebase.

$35

Buy Now

Red Label Edition

  • Confident Ruby in PDF, EPUB, and Kindle formats

Don’t have the scratch for any of these editions? Send me a postcard instead!

About the Author

Hi, I'm Avdi Grimm. I've been hacking on Ruby code for 10 years, and I'm still loving it! I'm head chef at RubyTapas, the author of Exceptional Ruby and Objects on Rails, and a co-host of the Ruby Rogues podcast. In my copious spare time I blog about software development at Virtuous Code.

I live in York County, Pennsylvania with my wife and a steadily incrementing number of children.