no after_initialize defined by default

A recent post on the StackOverflow beta (http://beta.stackoverflow.com/
questions/10808/ruby-mixins-and-calling-super-methods#11866 for those
who are on it) discusses a problem with chaining after_initialize
definitions from multiple mixin modules. The problem is that each
module must use alias_method_chain (or call super) to make sure the
other after_initialize calls are executed, but models don't define
after_initialize by default. The first module included can't chain to
the non-existent definition.

The proof:

class Foo < ActiveRecord::Base
end

Foo.method_defined? :after_initialize
=> false

The solution is

ActiveRecord::Base
  def after_initialize
    #nothing
  end
end

I can see a counter-argument to putting this in core: if you're going
to include the mixin, you should be defining it yourself. But I'm not
convinced. I don't see any reason why there aren't default (empty)
implementations of every callback method. Doing so would obviate the
check during object creation, which can only be a good thing.

I can see a counter-argument to putting this in core: if you're going
to include the mixin, you should be defining it yourself. But I'm not
convinced. I don't see any reason why there aren't default (empty)
implementations of every callback method. Doing so would obviate the
check during object creation, which can only be a good thing.

See this reasoning as listed in the rdoc:

  # == The +after_find+ and +after_initialize+ exceptions