Issue #16902 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Open to Rejected

16 and 17 call `moo` method on different objects.
`Hash`s store frozen copies of `String` keys, otherwise if a key gets modified then the element associated to the modified key can no longer be accessed, until `rehash`ed.
As this "copy" is not made with `clone` method, extended `Module`s are not copied.

----------------------------------------
Bug #16902: Enumerable#group_by invalid key object
https://bugs.ruby-lang.org/issues/16902#change-85726

* Author: tonobo (Tim Foerster)
* Status: Rejected
* Priority: Normal
* ruby -v: ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I actually want to group by a customized string object and it seems to be ignored. I've tested this with ruby 2.5 and 2.7 and the behavior seems to be the same. Not really sure if this is expected, but the documentation means it's grouped by the block result.

``` ruby
[15] pry(main)> Moo = Module.new{def moo; "hui"; end}
=> Moo
[16] pry(main)> [+'moo'.extend(Moo), +'moo'.extend(Moo)].group_by{ _1 }['moo'].map(&:moo)
=> ["hui", "hui"]
[17] pry(main)> [+'moo'.extend(Moo), +'moo'.extend(Moo)].group_by{ _1 }.keys.map(&:moo)
NoMethodError: undefined method `moo' for "moo":String
from (pry):17:in `map'

```






-- 
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>