Merge pull request #5646 from koic/support_array_join_with_string_argument

Make `Array#*` the CRuby compatible behavior when giving a string argument
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-02-11 15:21:01 +09:00
committed by GitHub
2 changed files with 9 additions and 1 deletions
+7 -1
View File
@@ -425,9 +425,15 @@ mrb_ary_times(mrb_state *mrb, mrb_value self)
{
struct RArray *a1 = mrb_ary_ptr(self);
struct RArray *a2;
mrb_value *ptr;
mrb_value *ptr, sep, tmp;
mrb_int times, len1;
mrb_get_args(mrb, "o", &sep);
tmp = mrb_check_string_type(mrb, sep);
if (!mrb_nil_p(tmp)) {
return mrb_ary_join(mrb, self, tmp);
}
mrb_get_args(mrb, "i", &times);
if (times < 0) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "negative argument");