Ruby Metaprograming

Posted by jgrant, 2006-10-15 19:10:00


Ola Bini's Ruby Metaprogramming techniques is a great summary of the meta-programming techniques in common use today by many of the interesting Ruby libraries.

Namely:

  1. Use the singleton-class
  2. Write DSL's using class-methods that rewrite subclasses
  3. Create classes and modules dynamically
  4. Use method_missing to do interesting things
  5. Dispatch on method-patterns
  6. Replacing methods
  7. Use NilClass to implement the Introduce Null Object refactoring
  8. Learn the different versions of eval
  9. Introspect on instance variables
  10. Create Procs from blocks and send them around
  11. Use binding to control your evaluations

  • Other good resources on this topic:*