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]
parent 75ae3d3e
......@@ -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;
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment