Do you need to write Ruby code that is easy to maintain and change? With metaprogramming, you can produce elegant and clean programs.

Once the domain of expert Rubyists, metaprogramming is now accessible to programmers of all levels thanks to “Metaprogramming Ruby 2: Program Like the Ruby Pros” ( The 250-page book (which costs US$38 for a print edition and $25 for an ebook version) explains metaprogramming in a down-to-earth style and arms you with a practical toolbox.

In the book, you’ll learn metaprogramming as an essential component of Ruby and discover the deep, non-obvious details of the language. Once you understand the tenets of Ruby, including the object model, scopes, and singleton classes, you’re on your way to applying metaprogramming both in your daily work assignments and in your fun, after-hours projects. The book is packed with:

° Pragmatic examples of metaprogramming in action, many of which come straight from real-life gems such as Rails.

° Programming challenges that let you experiment and play with some of the most out-there metaprogramming concepts.

° Metaprogramming “spells”—33 practical recipes and idioms that you can study and apply right now, to write code that is sure to impress.

This completely revised new edition covers the new features in Ruby 2.0 and 2.1, and contains code from the latest Ruby libraries, including Rails 4. Most examples are new, “from the wild,” with more recent libraries. And the book reflects current ideas of when and how much metaprogramming you should use.

Author Paolo Perrotta has fifteen years of experience as a developer, ranging from embedded to enterprise software, computer games, and web applications. Paolo lives a nomadic life, mentoring agile teams throughout Europe. He has a base camp in Bologna, Italy.