From 5b62fbc0fc09fc00a327c0151a6049b6c5b90d99 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 19 Sep 2022 08:25:00 +0900 Subject: [PATCH] array.c (mrb_ary_concat_m): Array#concat to take multiple arguments. --- src/array.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/array.c b/src/array.c index 8f2b04d20..a3460c516 100644 --- a/src/array.c +++ b/src/array.c @@ -339,13 +339,29 @@ mrb_ary_concat(mrb_state *mrb, mrb_value self, mrb_value other) ary_concat(mrb, mrb_ary_ptr(self), a2); } +/* + * call-seq: + * array.concat(*other_arrays) -> self + * + * Adds to +array+ all elements from each \Array in +other_arrays+; returns +self+: + * + * a = [0, 1] + * a.concat([2, 3], [4, 5]) # => [0, 1, 2, 3, 4, 5] + */ + static mrb_value mrb_ary_concat_m(mrb_state *mrb, mrb_value self) { - mrb_value ary; + mrb_value *args; + mrb_int len; - mrb_get_args(mrb, "A", &ary); - mrb_ary_concat(mrb, self, ary); + mrb_get_args(mrb, "*!", &args, &len); + for (int i=0; i self + * + * Prepends the given +objects+ to +self+: + * + * a = [:foo, 'bar', 2] + * a.unshift(:bam, :bat) # => [:bam, :bat, :foo, "bar", 2] + * + * Array#prepend is an alias for Array#unshift. + * + * Related: #push, #pop, #shift. + */ + static mrb_value mrb_ary_unshift_m(mrb_state *mrb, mrb_value self) {