From: marcandre-ruby-core@... Date: 2021-07-01T20:16:46+00:00 Subject: [ruby-core:104464] [Ruby master Bug#17757] Hash#slice does not keep compare_by_identity on the results Issue #17757 has been updated by marcandre (Marc-Andre Lafortune). Thanks for the PR @jeremyevans0, looks pretty good. On the other hand, I'd like to revise what I wrote and suggest that `transform_keys` remain untouched. It's the only one of these methods that changes the keys so has a reason to interpret them differently. Matz, do you agree? ---------------------------------------- Bug #17757: Hash#slice does not keep compare_by_identity on the results https://bugs.ruby-lang.org/issues/17757#change-92720 * Author: kachick (Kenichi Kamiya) * Status: Open * Priority: Normal * ruby -v: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- GH-PR: https://github.com/ruby/ruby/pull/4330 ```console $ ruby -v ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20] ``` ```ruby str1 = +'str' str2 = +'str' hash = {a: :a, b: :b, c: :c}.compare_by_identity hash[str1] = 1 hash[str2] = 2 p hash.values_at(str1, str2) #=> [1, 2] p hash.except.compare_by_identity? #=> true p hash.slice.compare_by_identity? #=> false p hash.except(str1, str2) #=> {:a=>:a, :b=>:b, :c=>:c} p hash.slice(str1, str2) #=> {"str"=>2} ``` Is this an intentional behavior? I would expect Hash#slice keeps compare_by_identity behaviors. -- https://bugs.ruby-lang.org/ Unsubscribe: