From c308fec0f543c5b5a95bf529b5885964ae8b0f61 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 15 Dec 2014 15:45:25 +0100 Subject: [PATCH] autoloading guide: more refinements [ci skip] --- .../constant_autoloading_and_reloading.md | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/guides/source/constant_autoloading_and_reloading.md b/guides/source/constant_autoloading_and_reloading.md index 14100fb69c..88098236a0 100644 --- a/guides/source/constant_autoloading_and_reloading.md +++ b/guides/source/constant_autoloading_and_reloading.md @@ -261,14 +261,15 @@ in constant tables. ### Resolution Algorithm for Relative Constants At any given place in the code, let's define *cref* to be the first element of -the nesting if it is not empty, or `Object` otherwise. Without getting too much -into the details, the resolution algorithm for relative constant references goes -like this: +the nesting if it is not empty, or `Object` otherwise. -1. First, if the nesting is not empty it looks for the constant in its elements -and in order, ignoring their ancestors. +Without getting too much into the details, the resolution algorithm for relative +constant references goes like this: -2. If not found, then it walks up the ancestor chain of the cref. +1. If the nesting is not empty the constant is looked up in its elements and in +order. The ancestors of those elements are ignored. + +2. If not found, then the algorithm walks up the ancestor chain of the cref. 3. If not found, `const_missing` is invoked on the cref. @@ -286,9 +287,9 @@ Billing::Invoice `Billing::Invoice` is composed of two constants: `Billing`, in the first segment, is relative and is resolved using the algorithm of the previous -section; `Invoice`, in the secong segment, is qualified by `Billing` and we are +section; `Invoice`, in the second segment, is qualified by `Billing` and we are going to see its resolution next. Let's call *parent* to that qualifying class -or module object: +or module object, that is, `Billing` in the example above: 1. The constant is looked up in the parent and its ancestors. @@ -588,14 +589,14 @@ For example, consider ```ruby module Admin - User # relative reference + User end ``` and ```ruby -Admin::User # qualified reference +Admin::User ``` If `User` is missing, in either case all Rails knows is that a constant called