From 0dd5433b98afb0411449a4fd45dd0f918126c4ec Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Tue, 28 Dec 2010 14:13:43 +1000 Subject: [PATCH] Cover the inherited method from Rails::Railtie being used when I18n::Railtie is loaded. --- railties/guides/source/initialization.textile | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 738d5cf71a3..10937626af5 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -723,7 +723,39 @@ This file is the first file that sets up configuration with these lines inside t config.i18n.fallbacks = ActiveSupport::OrderedOptions.new -The +config+ method here is defined on +Rails::Railtie+ and is defined like this: +By inheriting from +Rails::Railtie+ the +Rails::Railtie#inherited+ method is called: + + + def inherited(base) + unless base.abstract_railtie? + base.send(:include, Railtie::Configurable) + subclasses << base + end + end + + +This first checks if the Railtie that's inheriting it is a component of Rails itself: + + +ABSTRACT_RAILTIES = %w(Rails::Railtie Rails::Plugin Rails::Engine Rails::Application) + +... + +def abstract_railtie? + ABSTRACT_RAILTIES.include?(name) +end + + +Because +I18n::Railtie+ isn't in this list, +abstract_railtie?+ returns +false+. Therefore the +Railtie::Configurable+ module is included into this class and the +subclasses+ method is called and +I18n::Railtie+ is added to this new array. + + +def subclasses + @subclasses ||= [] +end + + + +The +config+ method used at the top of +I18n::Railtie+ is defined on +Rails::Railtie+ and is defined like this: def config