
Metaprogramming Ruby
by Paolo Perrotta · first published 2010
49mentions
33recommended by
39HN commenters
2009–2026first – last mentioned
85% recommend13% neutral3% critical
Why HN recommends it
Clear, approachable explanation of Ruby's object model that makes metaprogramming and Rails internals understandable; suits intermediate Rubyists and experienced programmers new to metaprogramming.
Summarised by Claude from recommending comments
Affiliate links. As an Amazon Associate I earn from qualifying purchases.







…and having been using it literally daily ever since, it's joyful to read from someone that is just starting. I also started with https://www.railstutorial.org/book, highly recommend it. I also loved Metaprogramming Ruby (Paolo Perrotta) - it's more advanced and starts to open your mind to how Rails magic DSL's were built. I just bought today "Rebuilding Rails" (https://rebuilding-rails.com/), heard great things about…
on “Ruby on Rails in a week” ↗…understand what's happening behind the scenes in rails until you understand the tools at work. If you've got the basics of Ruby down, get this book and take it to the next level http://www.amazon.com/Metaprogramming-Ruby-Program-Like-Pros... As for the gems in rails..study their code, learn what they try to do, then program it yourself, else you might spend forever fighting with poorly documented and fragile gems, that…
on “Ask HN: Suggestions for Starting with Ruby on Rails?” ↗For any struggling to understand Ruby's metaprogramming, the rather short and succinct Metaprogramming Ruby is an excellent read. There's a method to the madness of define_method, method_missing, the various eval methods, the difference between Blocks, Procs, and Lambdas. Most of it revolves around manipulating…
on “Benefits of Writing a DSL in Ruby” ↗My favourite books read lately are Here Comes Everybody by Clay Shirky and Perrotta's Metaprogramming Ruby. If you haven't read Free by Chris Anderson, it's also highly recommended. It's just an article, but Anarconomy by the Copenhagen Institute for Futures Studies was a very interesting read (http://www.cifs.dk/doc/medlemsrapporter/MR0309UK.pdf).…
on “Ask HN: Summer Reading Recommendations?” ↗Metaprogramming Ruby [0] explains Ruby's handling of scope really well. Also, you might enjoy a silly gem I wrote a while ago called ghost_attributes [1]. It uses closures to mimic attr_accessor. The funny thing about it…
on “Closures explained with JavaScript” ↗…Ruby http://ruby.bastardsbook.com/ (3) Pragmatic Studio Ruby Course - http://pragmaticstudio.com/ruby (4) Eloquent Ruby by Russ Olsen (5) http://www.rubymonk.com/ (6) http://www.rubykoans.com/ (7) Metaprogramming Ruby by Paolo Perrotta (8) codeschool.com (9) Michael Hartl's Rails Tutorial- http://ruby.railstutorial.org/ (10) The Rails 3 Way by Obie Fernandez (11) http://www.railscasts.com
on “List of Resources for Learning Ruby” ↗…language. It's strongly advised to use rubocop or a similar style guide -- and to temper that with good judgment, at least when it recommends avoiding `!!`. In addition to the Pickaxe book, I recommend Metaprogramming Ruby by Paolo Perrotta, and potentially the sequel to that book (which I have yet to read). Ruby lends itself to a very fluid style. One of the things that you may find less common is explicit variable assignment…
on “Fibers are the right solution to improve Ruby performance” ↗I don't plan on rewriting my Rails apps, but the talk is certainly food for thought. At the very least this is a nice explanation of Ruby metaprogramming techniques; pair it with Paolo Perrotta's "Metaprogramming Ruby" and you'll have a good handle on the subject.
on “Refactoring Ruby with Monads” ↗I would recommend Metaprogramming Ruby by Paolo Perrotta if you know how to program but are new to metaprogramming.
on “Ruby: The Last Eight Years” ↗Metaprogramming Ruby by Paolo Perrotta has the best explanation of Ruby's object system I've seen. It's a must-read for anyone working with Ruby, even if you have no interest in metaprogramming. Despite the title, it's a…
on “Ruby on Rails in a week” ↗You might try Metaprogramming Ruby 2 by Paolo Perrotta[1] (the link has bits you can read). I haven't read number 2, just number 1, but I'd expect it's pretty much the same. It's written with the conceit of an experienced programmer taking…
on “_why's Estate” ↗Metaprogramming Ruby by Paolo Perrotta is an awesome in-depth resource in comparison. It’s a bit outdated but the base of metaprogramming magic in Ruby hasn’t changed much in 3.0+
on “An Introduction to Metaprogramming in Ruby” ↗Metaprogramming Ruby by Paolo Perrotta
on “Ask HN: Books you wish you had read earlier?” ↗…learn things? I haven't been to a talk in awhile and I just can't get into video learning. So FWIW, I'll throw in the Ruby-related-infothing that I was most excited about this year: the publishing of "Metaprogramming Ruby 2:" (https://pragprog.com/book/ppmetr2/metaprogramming-ruby-2)...The original version was one of the most helpful books to me as a Ruby beginner in 2010, both in learning the language and learning new ways…
on “Ruby talks of 2014” ↗…the language. Eloquent Javascript [1] does a good job of that and is also free. The best programming book at teaching a practical contemporary language in depth while teaching you to think with it is Metaprogramming Ruby. That's a great read for anyone considering writing a book to teach a programming language. And the best book I've ever read on thinking about programming comprehensively is SICP. Which again, I would…
on “Speaking JavaScript” ↗