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 feature: 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 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. 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 Need: Ruby 2.x, Ruby 1.9, or a recent version of JRuby. Reading this book was like diving into a new world of thinking. I tried a mix of Java and JRuby metaprogramming on a recent project. Using Java alone would now feel like entering a sword fight carrying only a banana, when my opponent is wielding a one-meter-long Samurai blade. - Sebastian Hennebrueder , Java Consultant and Trainer, laliluna.de This is the one book about Ruby that makes you go "So that's how it works" over and over again, as concepts such as the object model, DSLs, and blocks fall into place with that satisfying "Click!" sound. It's a great guide to what happens under the hood of a language that seems to involve a kind of magic deep inside. I highly recommend it. - Peter Bakhirev , Lead software engineer, Gilt City The previous edition of Metaprogramming Ruby changed my life and my code, and helped me get my first programming job. You would think there would be no way to improve on a book that good, but Paolo Perrotta has done it. Learn to unlock the hidden potential of this beautiful language, and fall in love with Ruby again. - Richard Schneeman , Programmer, Heroku For gem authors and application developers alike, this book lays down the foun- dation everyone needs to harness the full power of Ruby. Paolo describes metaprogramming in a fun and approachable way for all skill levels. The knowledge garnered from reading this book will help you write cleaner code and work more effectively with legacy codebases - Paul Elliott , Rocketeer, Hashrocket Metaprogramming Ruby has been a hugely influential book for me, especially during a time when I wanted to learn about the inner workings of Ruby. Paolo "Nusco" Perrotta made what is normally a complex topic fun, enjoyable, and very approachable. - Josh Kalderimis , CEO, Travis CI 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. He loves Ruby.