Unless you've been writing your Ruby code in a cave, deep within uninhabited mountains, you have probably seen and written a Ruby module. And it probably went something like this:
Including this into a User model gives us User.awesome, User.make_everyone_awesome, and User#awesome?.
Before getting into ActiveSupport::Concern, you shouldn't be defining the InstanceMethods module and explicitly including it. Remove it now, based on reasons explained by Yehuda Katz. I only provide it in this example for criticism.
In Rails 3, extend your module with ActiveSupport::Concern. This gives you two things:
- The including class is automatically extended with the ClassMethods module. No more klass.extend(ClassMethods).
- You get a new method called "included", which provides a terser way to define the idiomatic "self.include(base)" method.
As an aside, the Awesomeness module should definitely go into Rails core, but they keep ignoring my requests.