small medium large xlarge

Metaprogramming Ruby: Program Like the Ruby Pros


Cover image for Metaprogramming Ruby

Metaprogramming Ruby

Program Like the Ruby Pros


As a Ruby programmer, you already know how much fun it is. Now see how to unleash its power, digging under the surface and exploring the language’s most advanced features: a collection of techniques and tricks known as metaprogramming. Once the domain of expert Rubyists, metaprogramming is now accessible to programmers of all levels—from beginner to expert. Metaprogramming Ruby explains metaprogramming concepts in a down-to-earth style and arms you with a practical toolbox that will help you write great Ruby code.

Metaprogramming Ruby 2 is available here.

Customer Reviews

If you program in Ruby, buy this book. Twice. Ruby isn’t magic anymore, just great.

- Joe Alba

I’ve also had a lot of trouble finding a good way to pick up these metaprogramming techniques, and this book is bar-none the best way to do it. Paolo Perrotta makes it painless to learn Ruby’s most complex secrets and use them in practical applications

- Chris Bunch

In Ruby, the practitioners of metaprogramming have found a language where they are only constrained by their imagination. To reach mastery is hard, and even harder is to apply it tastefully. This book gives a grounding in the fundamentals of metaprogramming Ruby in such a way that anyone can pick it up and then immediately start using it. Paolo brings out the core of how simple metaprogramming can be in this book, and that is no easy task.

- Ola Bini

, ThoughtWorks

See All Reviews

What You Need

Ruby 1.8 or Ruby 1.9

Contents & Extracts

Full Table of Contents


  • Metaprogramming Ruby
    • Monday: The Object Model
    • Tuesday: Methods excerpt
    • Wednesday: Blocks
    • Thursday: Class Definitions
    • Friday: Code That Writes Code
    • Epilogue
  • Metaprogramming in Rails
    • The Design of ActiveRecord
    • Inside ActiveRecord
    • Metaprogramming Safely
  • Appendices
    • Common Idioms
    • Domain Specific Languages
    • Spell Book excerpt


Paolo Perrotta has more than ten years of experience as a developer and writer. He worked for domains ranging from embedded to enterprise software, computer games, and web applications. These days, Paolo coaches agile teams for Yoox, a large Internet fashion shop, and teaches Java to developers throughout Europe. He lives in Bologna, Italy, with his girlfriend and a cat. He loves Ruby.