alias method chain in a module
alias_method_chain is a neat little method that lets you cleanly override a core method in Rails. But I ran into syntax problems using it in a module. Here's the solution.
class Foo < ActiveRecord::Base
def find_with_bar( *args )
find_without_bar( *args )
class << self
alias_method_chain :find, :bar
The alias_method_chain will alias the original find to find_without_bar, and will alias find_with_bar to find.
The self.included method is called when the module is included in the Foo class. It extends the class methods with those defined in module ClassMethods. And then it does the alias_method_chain, on the Foo class (class << self).