Ruby Metaprogramming Episode 2: Sharing Behavior

Posted in Development on July 12, 2008


Ruby Metaprogramming Episode 2: Sharing Behavior

One of the primary goals of good design is to put the right behavior in the right place without duplication. We’ll see three ways Ruby excels at this:

  • Using prototype-based programming, where you can create hierarchies of objects with controlled sharing of both state and behavior, and without a class definition in sight.
  • using inheritance (but you can only watch this section after you’ve watched the included Public Safety announcement on why inheritance is normally a bad idea). We’ll also look at what happens when you do class << object (and why it’s nothing whatsoever to do with inheritance).
  • using modules and mixins, the sweet spot of Ruby programming. How to using include and extend, and how to create modules that mix in both instance and class methods.

Episodes one and two are the foundation for the rest of the screencast.

Watch Video

Tags: Ruby, Metaprogramming, The Pragmatic Programmers, Ruby Metaprogramming