---
title: "Ruby 2.5 has removed top level constant lookup"
description: "top level constant lookup has been removed in ruby 2.5"
canonical_url: "https://www.bigbinary.com/blog/ruby-2.5-has-removed-top-level-constant-lookup"
markdown_url: "https://www.bigbinary.com/blog/ruby-2.5-has-removed-top-level-constant-lookup.md"
---

# Ruby 2.5 has removed top level constant lookup

top level constant lookup has been removed in ruby 2.5

- Author: Amit Choudhary
- Published: October 18, 2017
- Categories: Ruby 2.5, Ruby

#### Ruby 2.4

```ruby
irb> class Project
irb> end
=> nil

irb> class Category
irb> end
=> nil

irb> Project::Category
(irb):5: warning: toplevel constant Category referenced by Project::Category
 => Category
```

Ruby 2.4 returns the top level constant with a warning if it is unable to find a
constant in the specified scope.

This does not work well in cases where we need constants to be defined with same
name at top level and also in the same scope.

#### Ruby 2.5.0-preview1

```ruby
irb> class Project
irb> end
=> nil

irb> class Category
irb> end
=> nil

irb> Project::Category
NameError: uninitialized constant Project::Category
Did you mean?  Category
	from (irb):5
```

Ruby 2.5 throws an error if it is unable to find a constant in the specified
scope.

Here is the relevant [commit](https://github.com/ruby/ruby/commit/44a2576f79)
and [discussion](https://bugs.ruby-lang.org/issues/11547).

## Links

- [Human page](https://www.bigbinary.com/blog/ruby-2.5-has-removed-top-level-constant-lookup)
