mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
+1
-1
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user