From: jacknagel@... Date: 2015-04-13T22:18:28+00:00 Subject: [ruby-core:68879] [Ruby trunk - Bug #10702] Constant look up inconsistency with constants defined in included modules Issue #10702 has been updated by Jack Nagel. I don't remember the details of the article, but if it is truly implying that the opening of D should have access to any constant accessible from C, then the article is wrong. But I don't think it is implying that. >either I should not be able to access B on line 9 The opening of C has access to B through C's inclusion (i.e., inheritance from) A. >or I should be able to access it on line 12 The opening of D has access to two sets of constants: those available lexically, and those available through inheritance. B is not part of either of these. ---------------------------------------- Bug #10702: Constant look up inconsistency with constants defined in included modules https://bugs.ruby-lang.org/issues/10702#change-52146 * Author: Kelly Stannard * Status: Rejected * Priority: Normal * Assignee: * ruby -v: 2.2-head * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- https://gist.github.com/kwstannard/c0f722976ba023cc5755 ```ruby module A module B end end module C include A puts B.inspect # => A::B class D puts B.inspect rescue puts 'failed' # => failed end B = B class E puts B.inspect # => A::B end end ``` When you include a module you gain access to that module's constants as seen in line 9. Line 19 shows that you can get constants defined in the nested module when the constant is defined within the module itself. Line 12 is the bug. Shouldn't class `D` be able to access module `B` since the previous line shows that module `C` has access to Module `B`? -- https://bugs.ruby-lang.org/