Project

General

Profile

Actions

Bug #17757

closed

Hash#slice does not keep compare_by_identity on the results

Added by kachick (Kenichi Kamiya) about 3 years ago. Updated almost 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
[ruby-core:103071]

Description

GH-PR: https://github.com/ruby/ruby/pull/4330

$ ruby -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0