`Hash#delete` should return the deleted value; fix #4133

parent a690aef8
...@@ -460,7 +460,7 @@ sg_del(mrb_state *mrb, seglist *t, mrb_value key, mrb_value *vp) ...@@ -460,7 +460,7 @@ sg_del(mrb_state *mrb, seglist *t, mrb_value key, mrb_value *vp)
} }
key2 = seg->e[i].key; key2 = seg->e[i].key;
if (!mrb_undef_p(key2) && sg_hash_equal(mrb, t, key, key2)) { if (!mrb_undef_p(key2) && sg_hash_equal(mrb, t, key, key2)) {
if (vp) *vp = key2; if (vp) *vp = seg->e[i].val;
seg->e[i].key = mrb_undef_value(); seg->e[i].key = mrb_undef_value();
t->size--; t->size--;
return TRUE; return TRUE;
......
...@@ -82,12 +82,12 @@ assert('Hash#default_proc', '15.2.13.4.7') do ...@@ -82,12 +82,12 @@ assert('Hash#default_proc', '15.2.13.4.7') do
end end
assert('Hash#delete', '15.2.13.4.8') do assert('Hash#delete', '15.2.13.4.8') do
a = { 'abc' => 'abc' } a = { 'abc' => 'ABC' }
b = { 'abc' => 'abc' } b = { 'abc' => 'ABC' }
b_tmp_1 = false b_tmp_1 = false
b_tmp_2 = false b_tmp_2 = false
a.delete('abc') assert_equal 'ABC', a.delete('abc')
b.delete('abc') do |k| b.delete('abc') do |k|
b_tmp_1 = true b_tmp_1 = true
end end
......
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