[ruby-core:103071] [Ruby master Bug#17757] Hash#slice does not keep compare_by_identity on the results
From:
kachick1@...
Date:
2021-03-28 12:25:34 UTC
List:
ruby-core #103071
Issue #17757 has been reported by kachick (Kenichi Kamiya).
----------------------------------------
Bug #17757: Hash#slice does not keep compare_by_identity on the results
https://bugs.ruby-lang.org/issues/17757
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>