Skip to content

Commit

Permalink
updates autoloading guide for Ruby 2.5 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Nov 1, 2017
1 parent 0931e17 commit a235b9f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion guides/source/autoloading_and_reloading_constants.md
Expand Up @@ -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**
Expand Down Expand Up @@ -1178,6 +1184,8 @@ end

#### Qualified References

WARNING. This gotcha is only possible in Ruby < 2.5.

Given

```ruby
Expand Down

0 comments on commit a235b9f

Please sign in to comment.