diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-17 15:14:23 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-03-17 15:14:23 +0900 |
| commit | c0d63ea09f41560f42c9d1f2605723fe5e6fa01c (patch) | |
| tree | 5e8f50af3ac966634471240a623a06091e6a0dd6 | |
| parent | 75ae3d3e23cf7c27d66c1eb14e0d09331aa1d8c7 (diff) | |
| download | mruby-c0d63ea09f41560f42c9d1f2605723fe5e6fa01c.tar.gz mruby-c0d63ea09f41560f42c9d1f2605723fe5e6fa01c.zip | |
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]
| -rw-r--r-- | src/hash.c | 2 | ||||
| -rw-r--r-- | test/t/hash.rb | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/hash.c b/src/hash.c index c30a8dec4..3b5d17761 100644 --- a/src/hash.c +++ b/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; diff --git a/test/t/hash.rb b/test/t/hash.rb index a5e51d83b..9bc2668ae 100644 --- a/test/t/hash.rb +++ b/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 |
