Issue #13142 has been updated by jeremyevans0 (Jeremy Evans).

Assignee set to keiju (Keiju Ishitsuka)
Status changed from Open to Assigned
File forwardable-constant-doc.patch added

From my testing, it looks like Ruby 2.2 was the first release to stop supporting nested constant lookup in `delegate`:

```
$ 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)
```

The documentation specifies that the argument to `delegate` 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:

```
ruby27 -rforwardable -e 'class M; ENUMERATOR = 1; extend Forwardable; delegate [:to_s] => "M::ENUMERATOR"; end; p M.new.to_s'
"1"
```

Attached is a patch to document how constant names are supported, and to add a test for the use of constants in forwardable.

----------------------------------------
Bug #13142: Forwardable regression: cannot delegate to a constant since 2.4.0
https://bugs.ruby-lang.org/issues/13142#change-78851

* Author: ch1c0t (Anatoly Chernow)
* Status: Assigned
* Priority: Normal
* Assignee: keiju (Keiju Ishitsuka)
* Target version: 
* ruby -v: 
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
Before this commit

https://github.com/ch1c0t/tra/commit/96b15f042183f488413db99d6ede304d20503cbd

it works just fine on 2.3. But on 2.4.0:

```
/usr/lib/ruby/2.4.0/forwardable.rb:222:in `take': uninitialized constant ENUMERATOR (NameError)
Did you mean?  Enumerator
               Enumerable
        from test.rb:16:in `<main>'
```

I report it because it might be an unintentional regression.

---Files--------------------------------
forwardable-constant-doc.patch (2.72 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>