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]
MODIFY
src/hash.c
src/hash.c
@@ -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;

MODIFY
test/t/hash.rb
test/t/hash.rb
@@ -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

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]