Unverified Commit 0ed3fcfa authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #5646 from koic/support_array_join_with_string_argument

Make `Array#*` the CRuby compatible behavior when giving a string argument
parents 11e7ca5d 182096d8
......@@ -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");
......
......@@ -32,6 +32,8 @@ assert('Array#*', '15.2.12.5.2') do
end
assert_equal([1, 1, 1], [1].*(3))
assert_equal([], [1].*(0))
assert_equal('abc', ['a', 'b', 'c'].*(''))
assert_equal('0, 0, 1, {:foo=>0}', [0, [0, 1], {foo: 0}].*(', '))
end
assert('Array#<<', '15.2.12.5.3') do
......
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