Metaprogramming Ruby: Program Like the Ruby Pros
Ruby is magical: it can manipulate itself at runtime. Few languages can do this. Ruby supports code that writes code (metaprogramming) in a more dynamic way than you can do using code generators or compilers. With Ruby, runtime isn’t set in concrete like an aging building. Instead, it’s more like a busy, thriving marketplace. Bits of code can walk up to other bits and ask them questions about themselves, and work out what to do next. These techniques make it far easier to extend and adapt existing programs as they’re running.
The problem is that metaprogramming techniques have been out of reach for common Rubyists—let alone for newbie Rubyites. But according to author and developer Paolo Perrotta, the flexibility and elegance of metaprogramming “isn’t an obscure art reserved for Ruby gurus.” In his new book, Metaprogramming Ruby: Program Like the Ruby Pros (Pragmatic Bookshelf, $32.95), Perrotta clearly describes 34 “spells” or language patterns that make metaprogramming understandable to Rubyists at all levels.
The book, Metaprogramming Ruby, uses stories and case studies to teach the techniques. Part 1, Metaprogramming Ruby, follows a new programmer as he learns the five core concepts: the object model, methods, blocks, class definitions, and code that writes code. Part 2, Metaprogramming in Rails, is presented as a case study. Readers closely examine source code in Rails—the flagship Ruby framework—and see how the masters actually use metaprogramming to develop real-world software.
Fun but provocative quizzes encourage readers to dig in—or to run off and think about the concepts. Three appendices expand the book, gathering useful idioms, resources on domain-specific languages, and a summary of the book’s magic spells for metaprogramming.
To Perrotta, there’s no reason for Ruby programmers to be intimidated by metaprogramming or to consider it a “bolt-on power feature.” He writes, “If you want to take the path to advanced Ruby coding, you’ll find metaprogramming at every step. Even if you’re happy with the amount of Ruby you already know and use, you’re still likely to stumble on metaprogramming in your coding travels: in the source of popular frameworks, in your favorite library, and even in small examples from random blogs. Until you master metaprogramming, you won’t be able to tap into the full power of the Ruby language.”
With Metaprogramming Ruby, new and experienced Rubyists can follow a practitioner’s journey to learn metaprogramming and then dive into examples of live code written by Ruby masters. Like the best teachers, Perrotta strips away what’s mysterious or intimidating about his subject—and delivers the magic.
About the Author
With more than ten years of experience as a developer and writer, Paolo Perrotta has worked in domains ranging from embedded software to enterprise software, computer games, and web applications. Based in Bologna, Italy, he coaches agile teams for Yoox, a large Internet fashion shop, and teaches Java to developers throughout Europe.
What People Are Saying
“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
Program Like the Ruby Pros
ISBN: 9781934356470, 296 pages, $32.95US, $41.95CA, 7.5×9.
Pragmatic Bookshelf Titles are distributed to bookstores internationally by O’Reilly Media.
Sample chapters, table of contents, and more information is available on the book’s home page.
About Pragmatic Bookshelf
The Pragmatic Bookshelf features books written by developers for developers. The titles continue the well-known Pragmatic Programmer style, and continue to garner awards and rave reviews. As development gets more and more difficult, the Pragmatic Programmers will be there with more titles and products to help programmers stay on top of their game.
Press and Editorial Queries Only:
Contact Andy Hunt or Dave Thomas
800-699-7764 (+1 919-847-3884)