aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/autoloading_and_reloading_constants.md
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2017-11-01 11:46:10 +0100
committerXavier Noria <fxn@hashref.com>2017-11-01 11:54:23 +0100
commita235b9f9d1656b6f47d1100f2fd07130ddaf1fa1 (patch)
tree6bb9450c90ad58379f7d2279373fac296310d755 /guides/source/autoloading_and_reloading_constants.md
parent0931e17ebf621e5518bc0546ea13268420f989ee (diff)
downloadrails-a235b9f9d1656b6f47d1100f2fd07130ddaf1fa1.tar.gz
rails-a235b9f9d1656b6f47d1100f2fd07130ddaf1fa1.tar.bz2
rails-a235b9f9d1656b6f47d1100f2fd07130ddaf1fa1.zip
updates autoloading guide for Ruby 2.5 [ci skip]
Diffstat (limited to 'guides/source/autoloading_and_reloading_constants.md')
-rw-r--r--guides/source/autoloading_and_reloading_constants.md10
1 files changed, 9 insertions, 1 deletions
diff --git a/guides/source/autoloading_and_reloading_constants.md b/guides/source/autoloading_and_reloading_constants.md
index ede0324a51..dea87a18f8 100644
--- a/guides/source/autoloading_and_reloading_constants.md
+++ b/guides/source/autoloading_and_reloading_constants.md
@@ -330,11 +330,17 @@ its resolution next. Let's define *parent* to be that qualifying class or module
object, that is, `Billing` in the example above. The algorithm for qualified
constants goes like this:
-1. The constant is looked up in the parent and its ancestors.
+1. The constant is looked up in the parent and its ancestors. In Ruby >= 2.5,
+`Object` is skipped if present among the ancestors. `Kernel` and `BasicObject`
+are still checked though.
2. If the lookup fails, `const_missing` is invoked in the parent. The default
implementation of `const_missing` raises `NameError`, but it can be overridden.
+INFO. In Ruby < 2.5 `String::Hash` evaluates to `Hash` and the interpreter
+issues a warning: "toplevel constant Hash referenced by String::Hash". Starting
+with 2.5, `String::Hash` raises `NameError` because `Object` is skipped.
+
As you see, this algorithm is simpler than the one for relative constants. In
particular, the nesting plays no role here, and modules are not special-cased,
if neither they nor their ancestors have the constants, `Object` is **not**
@@ -1178,6 +1184,8 @@ end
#### Qualified References
+WARNING. This gotcha is only possible in Ruby < 2.5.
+
Given
```ruby