So every now and then I like to do really stupid shit with the object model. I find it gives me a deeper understanding of exactly how Ruby functions and provides an exercise for my brain. Not all of this is stuff you'd want to do anywhere near production code, but it's sort of nice to know, and I thought I'd share. If people like it when I post it, I'll post more of it.
Here's today's silly trick:
Dynamically-Generated Mixins via a Mixin Factor
@keyword = keyword
This works because
include is just a method of Module that expects a Module, and
MixinFactory:: returns an anonymous Module. This particular one I actually use in production: we have several classes that have distinct Representers, with all of them used in the client code more or less the same way. So I have a MixinFactory that takes a Representer as a parameter and builds a Mixin that appropriately configures it, then includes that configuration in the client class.