We write about Ruby on Rails, React.js, React Native, remote work, open source, engineering and design.
1irb> class Project
2irb> end
3=> nil
4
5irb> class Category
6irb> end
7=> nil
8
9irb> Project::Category
10(irb):5: warning: toplevel constant Category referenced by Project::Category
11 => 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.
1irb> class Project
2irb> end
3=> nil
4
5irb> class Category
6irb> end
7=> nil
8
9irb> Project::Category
10NameError: uninitialized constant Project::Category
11Did you mean? Category
12 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 and discussion.