Monday, May 08, 2006

Grokking Ruby metaprogramming

I finally grok metaprogramming in Ruby and am happily generating methods into my subclasses. The trick I had to realize is that I need to view the generated methods as template methods available to "normal" methods. For example, if I have a graph method, it can call a generated filter method to filter what to graph. My monitoring system for the backend of Sharpcast is so much cleaner now.

Another way of describing Ruby metaprogramming--one of many styles--is that you avoid the cost of overriding methods in subclasses by generating the methods you want from the base class into the subclass.

0 Comments:

Post a Comment

<< Home