Section 6. Metaprogramming

Now it is going to get really interesting. Let’s leave the highways and return to the back roads to see places far off the beaten track: We are going to explore how Rails is built from metaprogramming. Metaprogramming is an umbrella concept that describes a variety of techniques for manipulating the very building blocks of the language. What we did with blocks and strings and objects was programming. Metaprogramming manipulates classes and methods instead and comprises a few related concepts:

  1. Reflection
  2. Message sending
  3. Method missing

These techniques are like wizardry: You can use them to do great things, but you should not attempt them unless you have some mastery. Naturally, all of them are also used to great effect ...

Get Rubyisms in Rails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.