diff options
Diffstat (limited to 'guides/source/constant_autoloading_and_reloading.md')
| -rw-r--r-- | guides/source/constant_autoloading_and_reloading.md | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/guides/source/constant_autoloading_and_reloading.md b/guides/source/constant_autoloading_and_reloading.md index afb5b6a694..effa66f19c 100644 --- a/guides/source/constant_autoloading_and_reloading.md +++ b/guides/source/constant_autoloading_and_reloading.md @@ -6,15 +6,10 @@ This guide documents how constant autoloading and reloading works. After reading this guide, you will know: * Key aspects of Ruby constants - * What is `autoload_paths` - * How constant autoloading works - * What is `require_dependency` - * How constant reloading works - * Solutions to common autoloading gotchas -------------------------------------------------------------------------------- @@ -225,7 +220,7 @@ constants on the fly. ### Constants are Stored in Modules Constants belong to modules in a very literal sense. Classes and modules have -a constant table, think of it as a hash table. +a constant table; think of it as a hash table. Let's analyze an example to really understand what that means. While in a casual setting some abuses of language are customary, the exposition is going @@ -405,11 +400,11 @@ is raised. We are going to cover how constant autoloading works in more detail later, but the idea is that when a constant like `Post` is hit and missing, if there's a -*post.rb* file for example in *app/models* Rails is going to find it, evaluate +`post.rb` file for example in `app/models` Rails is going to find it, evaluate it, and have `Post` defined as a side-effect. Alright, Rails has a collection of directories similar to `$LOAD_PATH` in which -to lookup that *post.rb*. That collection is called `autoload_paths` and by +to lookup that `post.rb`. That collection is called `autoload_paths` and by default it contains: * All subdirectories of `app` in the application and engines. For example, @@ -585,8 +580,8 @@ file is loaded. If the file actually defines `Post` all is fine, otherwise ### Qualified References When a qualified constant is missing Rails does not look for it in the parent -namespaces. But there's a caveat: unfortunately, when a constant is missing -Rails is not able to say if the trigger was a relative or qualified reference. +namespaces. But there is a caveat: When a constant is missing, Rails is +unable to tell if the trigger was a relative reference or a qualified one. For example, consider @@ -954,8 +949,8 @@ end require_dependency ‘square’ ``` -Only the leaves that are **at least grandchildren** have to be loaded that -way. Direct subclasses do not need to be preloaded and, if the hierarchy is +Only the leaves that are **at least grandchildren** need to be loaded this +way. Direct subclasses do not need to be preloaded. If the hierarchy is deeper, intermediate classes will be autoloaded recursively from the bottom because their constant will appear in the class definitions as superclass. |
