Jump to ratings and reviews
Rate this book

Metaprogramming Ruby 2: Program Like the Ruby Pros

Rate this book
Write powerful Ruby code that is easy to maintain and change. With metaprogramming, you can produce elegant, clean, and beautiful programs. Once the domain of expert Rubyists, metaprogramming is now accessible to programmers of all levels. This thoroughly revised and updated second edition of the bestselling Metaprogramming Ruby explains metaprogramming in a down-to-earth style and arms you with a practical toolbox that will help you write your best Ruby code ever.

Dig under the surface and explore Ruby's most advanced a collection of techniques and tricks known as metaprogramming. In this 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.

Metaprogramming Ruby, Second Edition makes mastering the language enjoyable. The book is packed

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.

Whether you're a Ruby apprentice on the path to mastering the language or a Ruby wiz in search of new tips, this book is for you.

What You

Ruby 2.x, Ruby 1.9, or a recent version of JRuby.

280 pages, Paperback

First published August 8, 2014

35 people are currently reading
241 people want to read

About the author

Paolo Perrotta

6 books11 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
136 (65%)
4 stars
54 (25%)
3 stars
17 (8%)
2 stars
1 (<1%)
1 star
0 (0%)
Displaying 1 - 13 of 13 reviews
Profile Image for Daniel Dao.
105 reviews30 followers
January 11, 2021
Good book that was well-written and enjoyable. Lots of programming books can be a chore / slog to read since they feel too informative. I particularly enjoyed the code examples from real libraries; it's always interesting to read other code in real-world examples.
Profile Image for Katherine.
883 reviews44 followers
October 29, 2016
omg I finally finished a non-fiction book, and a technical one, and this one in particular, at that! This book is excellent, really, but until I had learned some of the material piecemeal from my job and from watching talks, I couldn't get myself past the first couple chapters. I think also I had to come to accept that having to take breaks (and also possibly naps...) when reading programming books is just a thing for me.

Anyway, the explanations and examples are very good. I think I may finally understand the Ruby object model and method lookup process!!! I like that there's enough of a behind-the-scenes peek at why certain things are the way they are in Ruby, without bogging you down with excruciating detail. The framing narrative of pairing with expert Rubyist "Bill" is a little tedious at times, but he does mix in female pronouns here and there, so don't let that bug you too much.

I'm not sure how useful this information is necessarily for a straight up Rails developer, but if you want to understand Ruby the language better, this is great.
Profile Image for Szymon.
48 reviews5 followers
March 24, 2019
Dont make a mistake of just reading this book without trying out stuff on your own. A lot of topics went over my head and although I mark this book as read, I will be coming back to it, few pages at a time with my IDE open.
Profile Image for Anton Antonov.
350 reviews48 followers
July 20, 2024
Another one I've read in 2015.

I am partially repeating the same story from another book I just reviewed from 2015's reads. I wrote Ruby in a forex trading company. What I also omitted is that I worked for two companies, one in the first half of 2015 and the other in the second. Both had lots of experienced Ruby engineers around me.
I wanted to learn and understand it because I was curious about knowledge and had a passion for debate at the time.

Metaprogramming is a hot topic in Ruby and makes everyone feel smart when they meta-program.
Well, for the sake of knowing and practicing this when it was the smart thing to do, yes, the book was a good resource. It was straight to the point, with a good format of code snippets, quizzes, and quiz solutions. As simple as you'd expect.


At that time and still to this date, I don't recommend anyone put their make-pretend smartness into code that their colleagues have to read. If you're truly smart, you're going to write idiomatic code. :)
Profile Image for Andrew.
707 reviews8 followers
August 4, 2017
Between this and POODR, I have yet to find better books on Ruby. The Rails section was more of an object lesson for me, as it's very deep into the weeds with a particular framework.
Profile Image for Josué.
2 reviews
March 1, 2017
Outstanding way to describe metaprogramming and what are the best ways to achieve good programming skills regarding this technique. This one is a must to have, for all ruby developers.
Profile Image for Eric Brooke.
111 reviews18 followers
November 15, 2014
You have being programming in Ruby for a while and you need a book to step up your game. This introduces multiple meta programming concepts partly through a story of a mentor and mentoree, multiple examples and explains when you should use each techniques. It uses both code and pictures to describe the examples. Without a doubt one of my favourite Ruby books and I have most of them! Excellent work Paolo.
Profile Image for Vladimir Rybas.
4 reviews1 follower
January 16, 2016
Great introduction to the world of metaprogramming.
The author found a way to explain such a complex topic in fun and easy manner. A number of real world code examples and a few historical insights to Rails codebase give a pretty good representation on how to (and how not to) solve typical problems with metaprogramming.
Definitely a good read.
Profile Image for Bruno.
12 reviews2 followers
February 20, 2017
After reading this book, I could see the real power the Ruby lang has to offer. Metaprogramming is, by far, the most important concept for Ruby developers. I would recommend this book to anyone who has a good ruby experience and is seeking a good resource to take the knowledge to the next level.
Profile Image for Péricles Dantas.
1 review
June 26, 2016
best ruby book I've read so far! incredible to learn deep ruby secrets of metaprogramming.
Displaying 1 - 13 of 13 reviews

Can't find what you're looking for?

Get help and learn more about the design.