mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
+7
-1
@@ -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", ×);
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user