From 6777b7a886440a1faa9e29fcfa57a73a28128f68 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Tue, 28 Dec 2010 14:04:19 +1000 Subject: Init guide: finish covering the process of the i18n_railtie.rb file. --- railties/guides/source/initialization.textile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'railties/guides') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index ceee4639a2..738d5cf71a 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -850,6 +850,26 @@ The +on_load+ method here is provided by the +active_support/lazy_load_hooks+ fi end +The +@loaded+ variable here is a hash containing elements representing the different components of Rails that have been loaded at this stage. Currently, this hash is empty. So the +else+ is executed here, using the +@load_hooks+ variable defined in +active_support/lazy_load_hooks+: + + + @load_hooks = Hash.new {|h,k| h[k] = [] } + + +This defines a new hash which has keys that default to empty arrays. This saves Rails from having to do something like this instead: + + + @load_hooks[name] = [] + @load_hooks[name] << [block, options] + + +The value added to this array here consists of the block and options passed to +after_initialize+. + +We'll see these +@load_hooks+ used later on in the initialization process. + +This rest of +i18n_railtie.rb+ defines the protected class methods +include_fallback_modules+, +init_fallbacks+ and +validate_fallbacks+. + + **** REVIEW IS HERE **** This defines two methods on the module itself by using the familiar +class << self+ syntax. This allows you to call them as if they were class methods: +ActiveSupport.on_load_all+ and +ActiveSupport.load_all!+ respectively. The first method simply adds loading hooks to save them up for loading later on when +load_all!+ is called. By +call+'ing the block, the classes will be loaded. (NOTE: kind of guessing, I feel 55% about this). -- cgit v1.2.3