Issue #16902 has been reported by tonobo (Tim Foerster).

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

* Author: tonobo (Tim Foerster)
* Status: Open
* 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>