diff options
author | Kenichi Kamiya <kachick1@gmail.com> | 2021-03-27 12:55:46 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-27 12:55:46 +0900 |
commit | aceb8c0b4bf37a65c78f09eaf835db72c7a47c48 (patch) | |
tree | 02baafb15b9aa9fb1c45670932a25e1138a006f9 /enum.c | |
parent | 785c77d7827677b547fa233deef0b65ec10ecf6b (diff) |
Fix Enumerable#tally with some arguments pattern [Feature #17744]
* Add test cases for Enumerable#tally with hash argument
* Add ruby/spec for Enumerable#tally with hash argument
* Fix Enumerable#tally does not update given frozen hash
* Add test cases for Enumerable#tally with hash convertible arguments
* Fix SEGV when Enumerable#tally takes non Hash convertible
* FIx cosmetic damage enum.c
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4327
Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -1069,10 +1069,14 @@ static VALUE enum_tally(int argc, VALUE *argv, VALUE obj) { VALUE hash; - if (rb_check_arity(argc, 0, 1)) - hash = rb_check_hash_type(argv[0]); - else + if (rb_check_arity(argc, 0, 1)) { + hash = rb_convert_type(argv[0], T_HASH, "Hash", "to_hash"); + rb_check_frozen(hash); + } + else { hash = rb_hash_new(); + } + return enum_hashify_into(obj, 0, 0, tally_i, hash); } |