Actions
Bug #16902
closedEnumerable#group_by invalid key object
Bug #16902:
Enumerable#group_by invalid key object
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
Description
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.
[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'
Actions