Home > Articles > Programming > Ruby

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Metaprogramming Madness

While in most cases Ruby's dynamic nature provides great benefits, it can be misused. Some metaprogramming techniques can result in obfuscated code. The method_missing hook, for example, often results in code that is difficult to understand. It can be a powerful tool if an object's interface cannot be determined at coding time, but unless it's absolutely necessary I use Replace Dynamic Receptor with Dynamic Method Definition or even a simple Extract Method to remove the method_missing definition. If the method_missing definition is truly needed, I might use Isolate Dynamic Receptor to separate concerns.

  • + Share This
  • 🔖 Save To Your Account