https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-06-24T22:11:43ZRuby Issue Tracking SystemRuby master - Bug #13142: Forwardable regression: cannot delegate to a constant since 2.4.0https://bugs.ruby-lang.org/issues/13142?journal_id=788512019-06-24T22:11:43Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/7856">forwardable-constant-doc.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/7856/forwardable-constant-doc.patch">forwardable-constant-doc.patch</a> added</li><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>keiju (Keiju Ishitsuka)</i></li></ul><p>From my testing, it looks like Ruby 2.2 was the first release to stop supporting nested constant lookup in <code>delegate</code>:</p>
<pre><code>$ ruby21 -rforwardable -e 'class M; ENUMERATOR = 1; extend Forwardable; delegate [:to_s] => :ENUMERATOR; end; p M.new.to_s'
"1"
$ ruby22 -rforwardable -e 'class M; ENUMERATOR = 1; extend Forwardable; delegate [:to_s] => :ENUMERATOR; end; p M.new.to_s'
-e:1:in `<main>': uninitialized constant ENUMERATOR (NameError)
</code></pre>
<p>The documentation specifies that the argument to <code>delegate</code> should be a symbol or array of symbols, and the symbols correspond to method names (not constant names). However, as indicated by the error message, it turns out the constant names are supported, but you need to provide the full path of the constant:</p>
<pre><code>ruby27 -rforwardable -e 'class M; ENUMERATOR = 1; extend Forwardable; delegate [:to_s] => "M::ENUMERATOR"; end; p M.new.to_s'
"1"
</code></pre>
<p>Attached is a patch to document how constant names are supported, and to add a test for the use of constants in forwardable.</p> Ruby master - Bug #13142: Forwardable regression: cannot delegate to a constant since 2.4.0https://bugs.ruby-lang.org/issues/13142?journal_id=800632019-07-26T14:37:59Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Document and add spec for delegating to constants in Forwardable Fixes [Bug #13142]" href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/4b7d7d007fa5a06d237be6f379106feea25fca79">git|4b7d7d007fa5a06d237be6f379106feea25fca79</a>.</p>
<hr>
<p>Document and add spec for delegating to constants in Forwardable</p>
<p>Fixes [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Forwardable regression: cannot delegate to a constant since 2.4.0 (Closed)" href="https://bugs.ruby-lang.org/issues/13142">#13142</a>]</p>