hash.c: Hash#shift to return nil when a hash is empty.

It used to be return the default value if available, but it should
ignore the default value for behavior consistency. CRuby will adopt
this behavior too in the future. [ruby-bugs:16908]
This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-03-17 15:14:23 +09:00
parent 75ae3d3e23
commit c0d63ea09f
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -1506,7 +1506,7 @@ mrb_hash_shift(mrb_state *mrb, mrb_value hash)
hash_modify(mrb, hash);
if (h_size(h) == 0) {
return hash_default(mrb, hash, mrb_nil_value());
return mrb_nil_value();
}
else {
mrb_value del_key, del_val;
+2 -2
View File
@@ -775,7 +775,7 @@ assert('Hash#shift', '15.2.13.4.24') do
assert_equal(0, h.size)
h.default = -456
assert_equal(-456, h.shift)
assert_equal(nil, h.shift)
assert_equal(0, h.size)
h.freeze
@@ -783,8 +783,8 @@ assert('Hash#shift', '15.2.13.4.24') do
end
h = Hash.new{|h, k| [h, k]}
assert_operator(h.shift, :eql?, [h, nil])
assert_equal(0, h.size)
assert_equal(nil, h.shift)
end
# Not ISO specified