From: Avdi Grimm Date: 2008-03-07T04:19:34+09:00 Subject: Re: Best practices for Ruby Meta-programming On Thu, Mar 6, 2008 at 1:15 PM, James Britt wrote: > Don't be evil. > > Don't be stupid. So THAT's what I've been doing wrong all this time. Wish someone had clued me in sooner. My concrete contribution to this discussion: Modules are your friend. When tempted to dynamically extend a class with new methods, consider adding them to a module instead (potentially a dynamically created module using Module.new). Then use #include or #extend to add the module to your target. This has a number of benefits, including: * Clients can clearly see which which methods come from your extension vs. the methods that are part of the class itself, by using Ruby's reflection. * Clients can override dynamically created methods and still reuse them with #super() - no need to resort to aliasing. * A module can be re-used for either class-wide extension or extending a single object. -- Avdi