Chapter 9: Metaprogramming and When to Use It
Ruby has powerful metaprogramming capabilities, which is a double-edged sword. In the hands of a principled programmer, metaprogramming capabilities result in simpler, less verbose code. However, when misused, metaprogramming can result in code that is difficult to work with and hard to debug.
In this chapter, you'll learn about principles of responsible metaprogramming, so you can put metaprogramming to appropriate use in your libraries.
We will cover the following topics:
- Learning the pros and cons of abstraction
- Eliminating redundancy
- Understanding different ways of metaprogramming methods
- Using
method_missing
judiciously
By the end of this chapter, you'll have a better understanding of Ruby metaprogramming and how best to take advantage of it.