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

ruby-changes:63039

From: Jeremy <ko1@a...>
Date: Tue, 22 Sep 2020 11:35:28 +0900 (JST)
Subject: [ruby-changes:63039] df14c758fc (master): Make hash returned by Hash#transform_values not have a default

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

From df14c758fc705c49c2aaf4c9276a8f7229438fbf Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Mon, 21 Sep 2020 15:02:20 -0700
Subject: Make hash returned by Hash#transform_values not have a default

This sets an explicit default of nil.  There is probably a better
approach of removing the default.

Fixes [Bug #17181]

diff --git a/hash.c b/hash.c
index c20ceb3..2ccf8ec 100644
--- a/hash.c
+++ b/hash.c
@@ -3350,6 +3350,7 @@ rb_hash_transform_values(VALUE hash) https://github.com/ruby/ruby/blob/trunk/hash.c#L3350
 
     RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size);
     result = hash_copy(hash_alloc(rb_cHash), hash);
+    SET_DEFAULT(result, Qnil);
 
     if (!RHASH_EMPTY_P(hash)) {
         rb_hash_stlike_foreach_with_replace(result, transform_values_foreach_func, transform_values_foreach_replace, result);
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index e63fdf3..91e14da 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1696,6 +1696,7 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L1696
     x.default_proc = proc {|h, k| k}
     y = x.transform_values {|v| v ** 2 }
     assert_nil(y.default_proc)
+    assert_nil(y.default)
 
     y = x.transform_values.with_index {|v, i| "#{v}.#{i}" }
     assert_equal(%w(1.0  2.1  3.2), y.values_at(:a, :b, :c))
-- 
cgit v0.10.2


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

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