mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Make mutating the result of SortedSet#to_a not affect the set
Fixes [Bug #15834]
This commit is contained in:
parent
e100fcbdd1
commit
a6cf2f3d22
Notes:
git
2020-06-12 06:02:22 +09:00
2 changed files with 4 additions and 1 deletions
|
@ -778,7 +778,7 @@ class SortedSet < Set
|
|||
|
||||
def to_a
|
||||
(@keys = @hash.keys).sort! unless @keys
|
||||
@keys
|
||||
@keys.dup
|
||||
end
|
||||
|
||||
def freeze
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue