ruby-changes:61685
From: Jeremy <ko1@a...>
Date: Fri, 12 Jun 2020 06:02:15 +0900 (JST)
Subject: [ruby-changes:61685] a6cf2f3d22 (master): Make mutating the result of SortedSet#to_a not affect the set
https://git.ruby-lang.org/ruby.git/commit/?id=a6cf2f3d22 From a6cf2f3d22a78aeae9d7f36cc78a195deb686705 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Sun, 27 Oct 2019 16:03:07 -0700 Subject: Make mutating the result of SortedSet#to_a not affect the set Fixes [Bug #15834] diff --git a/lib/set.rb b/lib/set.rb index b8ab6ab..d405d81 100644 --- a/lib/set.rb +++ b/lib/set.rb @@ -778,7 +778,7 @@ class SortedSet < Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L778 def to_a (@keys = @hash.keys).sort! unless @keys - @keys + @keys.dup end def freeze diff --git a/test/test_set.rb b/test/test_set.rb index 68ee7ce..86f8602 100644 --- a/test/test_set.rb +++ b/test/test_set.rb @@ -800,6 +800,9 @@ class TC_SortedSet < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_set.rb#L800 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/