https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-12-18T00:08:56ZRuby Issue Tracking SystemRuby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredhttps://bugs.ruby-lang.org/issues/16430?journal_id=831962019-12-18T00:08:56Zsawa (Tsuyoshi Sawada)
<ul></ul><p>What is the purpose of writing the code in three different files? It only looks to me that it is making things more complicated.</p>
<p>A::B.foo and A::C.foo are undefined, and return a NoMethodError, as expected. If you meant A::B#foo and A::C#foo, then they do not make sense because A::B and A::C are modules, not classes.</p> Ruby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredhttps://bugs.ruby-lang.org/issues/16430?journal_id=831982019-12-18T01:18:28Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Is duplicate of</strong> <i><a class="issue tracker-1 status-6 priority-4 priority-default closed" href="/issues/11705">Bug #11705</a>: Namespace resolution in nested modules with short syntax</i> added</li></ul> Ruby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredhttps://bugs.ruby-lang.org/issues/16430?journal_id=832002019-12-18T01:20:42Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>It is by design. See "Scope" section of <a href="https://github.com/ruby/ruby/blob/master/doc/syntax/modules_and_classes.rdoc" class="external">https://github.com/ruby/ruby/blob/master/doc/syntax/modules_and_classes.rdoc</a></p> Ruby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredhttps://bugs.ruby-lang.org/issues/16430?journal_id=833012019-12-21T02:23:50ZMikeVastola (Mike Vastola)Mike@Vasto.la
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li><li><strong>ruby -v</strong> deleted (<del><i>ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]</i></del>)</li><li><strong>Backport</strong> deleted (<del><i>2.5: UNKNOWN, 2.6: UNKNOWN</i></del>)</li></ul><p>mame (Yusuke Endoh) wrote:</p>
<blockquote>
<p>It is by design. See "Scope" section of <a href="https://github.com/ruby/ruby/blob/master/doc/syntax/modules_and_classes.rdoc" class="external">https://github.com/ruby/ruby/blob/master/doc/syntax/modules_and_classes.rdoc</a></p>
</blockquote>
<p>Ok, I see that, but is this a good design? I would argue not and am therefore changing this to a feature request (I would ask it be re-opened.)</p>
<p>For me, this is literally the first instance -- having worked heavily with Ruby for the past 7 or so years -- wherein I have encountered something in the language that I found to be completely unintuitive.</p>
<p>Further, the documentation linked states "This style has the benefit of allowing the author to reduce the amount of indentation. Instead of 3 levels of indentation only one is necessary." this benefit is heavily attenuated if it is not possible to maintain the same scope as the more heavily indented syntax.</p>
<p>For the feature request, I would suggest either adding any parent namespaces to the nesting, or else (if there is concern about this being a breaking change) add a variant for the scope resolution operator in declaring a class/module to alter how nesting is interpreted (maybe <code>A:::B</code> -- a triple colon)?</p>
<p>Lastly, I would argue that there are far fewer (if any) use cases for the current design than for what I am suggesting.</p> Ruby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredhttps://bugs.ruby-lang.org/issues/16430?journal_id=833022019-12-21T02:25:42ZMikeVastola (Mike Vastola)Mike@Vasto.la
<ul></ul><p>sawa (Tsuyoshi Sawada) wrote:</p>
<blockquote>
<p>What is the purpose of writing the code in three different files? It only looks to me that it is making things more complicated.</p>
</blockquote>
<p>I was trying to offer a minimal (non)-working example. The benefit arises when there is more code and it makes sense to separate out features into their own files/nested modules.</p>
<blockquote>
<p>A::B.foo and A::C.foo are undefined, and return a NoMethodError, as expected. If you meant A::B#foo and A::C#foo, then they do not make sense because A::B and A::C are modules, not classes.</p>
</blockquote>
<p>My mistake. I meant to write <code>self.foo</code>. I will fix.</p> Ruby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredhttps://bugs.ruby-lang.org/issues/16430?journal_id=833032019-12-21T02:27:31ZMikeVastola (Mike Vastola)Mike@Vasto.la
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/83303/diff?detail_id=55885">diff</a>)</li></ul><p>Fixed small bug in initial description.</p> Ruby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredhttps://bugs.ruby-lang.org/issues/16430?journal_id=833042019-12-21T03:50:54Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Is duplicate of</strong> <i><a class="issue tracker-2 status-2 priority-4 priority-default" href="/issues/6810">Feature #6810</a>: `module A::B; end` is not equivalent to `module A; module B; end; end` with respect to constant lookup (scope)</i> added</li></ul> Ruby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredhttps://bugs.ruby-lang.org/issues/16430?journal_id=833072019-12-21T03:52:14Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>If you want to request a feature, please research the old tickets. I've found <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: `module A::B; end` is not equivalent to `module A; module B; end; end` with respect to constant l... (Assigned)" href="https://bugs.ruby-lang.org/issues/6810">#6810</a>.</p> Ruby master - Feature #16430: Resultion of constants in enclosing class/module affected by how nested classes/modules are declaredhttps://bugs.ruby-lang.org/issues/16430?journal_id=833082019-12-21T13:45:57ZMikeVastola (Mike Vastola)Mike@Vasto.la
<ul></ul><p>mame (Yusuke Endoh) wrote:</p>
<blockquote>
<p>If you want to request a feature, please research the old tickets. I've found <a class="issue tracker-2 status-2 priority-4 priority-default" title="Feature: `module A::B; end` is not equivalent to `module A; module B; end; end` with respect to constant l... (Assigned)" href="https://bugs.ruby-lang.org/issues/6810">#6810</a>.</p>
</blockquote>
<p>Ok, thanks. I tried searching before submitting this, but I apparently didn't use the right terms.</p>