The after_find and after_initialize callbacks work fine when defined as instance methods like so:
class User < ActiveRecord::Base
def after_initialize
[self.name](http://self.name) = 'Mc Gumbo'
end
end
User.new.name # => ‘Mc Gumbo’
But the alternative version doesn’t get fired:
class User < ActiveRecord::Base
after_initialize :name_mc_gumbo
def name_mc_gumbo
[self.name](http://self.name) = 'Mc Gumbo'
end
end
User.new.name # => nil
The funny thing is that the second form raises no errors, properly defines the callback, and is just waiting for the callback to be triggered. All it would take (I think) to make it work and not decrease performance changing the ActiveRecord::Base.instantiate from this:
if object.respond_to_without_attributes?(:after_initialize)
object.send(:callback, :after_initialize)
end
to this:
if object.respond_to_without_attributes?(:after_initialize) || object.class.instance_variable_get(“@after_initialize_callbacks”)
object.send(:callback, :after_initialize)
end
Is this worth a ticket or am I missing something?
::Jack Danger