Make mutating the result of SortedSet#to_a not affect the set

Fixes [Bug #15834]
This commit is contained in:
Jeremy Evans 2019-10-27 16:03:07 -07:00
parent e100fcbdd1
commit a6cf2f3d22
Notes: git 2020-06-12 06:02:22 +09:00
2 changed files with 4 additions and 1 deletions

View File

@ -778,7 +778,7 @@ class SortedSet < Set
def to_a
(@keys = @hash.keys).sort! unless @keys
@keys
@keys.dup
end
def freeze

View File

@ -800,6 +800,9 @@ class TC_SortedSet < Test::Unit::TestCase
def test_sortedset
s = SortedSet[4,5,3,1,2]
a = s.to_a
assert_equal([1,2,3,4,5], a)
a << -1
assert_equal([1,2,3,4,5], s.to_a)
prev = nil