[前][次][番号順一覧][スレッド一覧]

ruby-changes:63899

From: Akinori <ko1@a...>
Date: Fri, 4 Dec 2020 19:44:58 +0900 (JST)
Subject: [ruby-changes:63899] 46fc8d78a5 (master): [ruby/set] Resurrect support for Ruby 2.x

https://git.ruby-lang.org/ruby.git/commit/?id=46fc8d78a5

From 46fc8d78a5d23d3c9a24e1bcc3c5cde4bce888de Mon Sep 17 00:00:00 2001
From: Akinori MUSHA <knu@i...>
Date: Sun, 20 Sep 2020 23:23:13 +0900
Subject: [ruby/set] Resurrect support for Ruby 2.x

In Ruby 2.x, initialize_copy does not take a freeze option.

https://github.com/ruby/set/commit/3da6c309df

diff --git a/lib/set.rb b/lib/set.rb
index d405d81..844d52e 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -136,10 +136,18 @@ class Set https://github.com/ruby/ruby/blob/trunk/lib/set.rb#L136
     @hash = orig.instance_variable_get(:@hash).dup
   end
 
-  # Clone internal hash.
-  def initialize_clone(orig, freeze: nil)
-    super
-    @hash = orig.instance_variable_get(:@hash).clone(freeze: freeze)
+  if Kernel.instance_method(:initialize_clone).arity != 1
+    # Clone internal hash.
+    def initialize_clone(orig, **options)
+      super
+      @hash = orig.instance_variable_get(:@hash).clone(**options)
+    end
+  else
+    # Clone internal hash.
+    def initialize_clone(orig)
+      super
+      @hash = orig.instance_variable_get(:@hash).clone
+    end
   end
 
   def freeze    # :nodoc:
diff --git a/test/test_set.rb b/test/test_set.rb
index 86f8602..acb1ceb 100644
--- a/test/test_set.rb
+++ b/test/test_set.rb
@@ -739,7 +739,7 @@ class TC_Set < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_set.rb#L739
     set2.add 5
     assert_equal Set[1,2,3,5], set2
     assert_equal Set[1,2,3], set1
-  end
+  end if Kernel.instance_method(:initialize_clone).arity != 1
 
   def test_inspect
     set1 = Set[1, 2]
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]