Actions
Bug #19113
closedInconsistency in retention of compare_by_identity flag in Hash methods
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.0dev (2022-11-07T17:29:28Z master 9001e53e68) [x86_64-openbsd7.2]
Description
Hash.[]
and Hash.ruby2_keywords_hash
retain the compare_by_identity flag for non-empty hashes, but do not retain it for empty hashes:
hs = [{}.compare_by_identity, {:a=>1}.compare_by_identity]
hs.map{|h| Hash[h].compare_by_identity?}
# => [false, true]
hs.map{|h| Hash.ruby2_keywords_hash(h).compare_by_identity?}
# => [false, true]
This inconsistency seems like a bug.
Hash#compact
always drops the compare_by_identity flag, but it is documented as returning a copy of self, implying the compare_by_identity flag is kept (since #dup and #clone retain the flag).
{}.compare_by_identity.compact.compare_by_identity?
# => false
I'm not sure whether is a bug, because it is consistent, but I think retaining the flag makes more sense.
I'll try to work on a fix for both of these issues tomorrow.
Actions
Like1
Like1Like0Like0Like0Like0Like0Like0Like0Like0Like0