Project

General

Profile

Feature #12333 » fixed_multi_concat_prepend.patch

spinute (Satoru Horie), 05/03/2016 08:03 AM

View differences:

array.c
/*
* call-seq:
* ary.concat(other_ary) -> ary
* ary.concat(other_ary1, other_ary2,...) -> ary
*
* Appends the elements of +other_ary+ to +self+.
* Appends the elements of +other_ary+s to +self+.
*
* [ "a", "b" ].concat( ["c", "d"] ) #=> [ "a", "b", "c", "d" ]
* [ "a" ].concat( ["b"], ["c", "d"] ) #=> [ "a", "b", "c", "d" ]
* [ "a" ].concat #=> [ "a" ]
*
* a = [ 1, 2, 3 ]
* a.concat( [ 4, 5 ] )
* a #=> [ 1, 2, 3, 4, 5 ]
*
* a = [ 1, 2 ]
* a.concat(a, a) #=> [1, 2, 1, 2, 1, 2]
*
* See also Array#+.
*/
......
return x;
}
static VALUE
rb_ary_concat_m(int argc, VALUE *argv, VALUE ary)
{
VALUE args = rb_ary_new();
for (int i = 0; i < argc; i++)
rb_ary_concat(args, argv[i]);
rb_ary_concat(ary, args);
return ary;
}
/*
* call-seq:
......
rb_define_method(rb_cArray, "fetch", rb_ary_fetch, -1);
rb_define_method(rb_cArray, "first", rb_ary_first, -1);
rb_define_method(rb_cArray, "last", rb_ary_last, -1);
rb_define_method(rb_cArray, "concat", rb_ary_concat, 1);
rb_define_method(rb_cArray, "concat", rb_ary_concat_m, -1);
rb_define_method(rb_cArray, "<<", rb_ary_push, 1);
rb_define_method(rb_cArray, "push", rb_ary_push_m, -1);
rb_define_method(rb_cArray, "pop", rb_ary_pop_m, -1);
string.c
return str1;
}
static VALUE
rb_str_concat_m(int argc, VALUE *argv, VALUE str)
{
VALUE args = rb_str_new(0, 0);
for (int i = 0; i < argc; i++)
rb_str_concat(args, argv[i]);
rb_str_concat(str, args);
return str;
}
/*
* call-seq:
* str.prepend(other_str) -> str
......
return str;
}
static VALUE
rb_str_prepend_m(int argc, VALUE *argv, VALUE str)
{
VALUE args = rb_str_new(0, 0);
for (int i = 0; i < argc; i++)
rb_str_concat(args, argv[i]);
rb_str_prepend(str, args);
return str;
}
st_index_t
rb_str_hash(VALUE str)
{
......
rb_define_method(rb_cString, "codepoints", rb_str_codepoints, 0);
rb_define_method(rb_cString, "reverse", rb_str_reverse, 0);
rb_define_method(rb_cString, "reverse!", rb_str_reverse_bang, 0);
rb_define_method(rb_cString, "concat", rb_str_concat, 1);
rb_define_method(rb_cString, "concat", rb_str_concat_m, -1);
rb_define_method(rb_cString, "<<", rb_str_concat, 1);
rb_define_method(rb_cString, "prepend", rb_str_prepend, 1);
rb_define_method(rb_cString, "prepend", rb_str_prepend_m, -1);
rb_define_method(rb_cString, "crypt", rb_str_crypt, 1);
rb_define_method(rb_cString, "intern", rb_str_intern, 0); /* in symbol.c */
rb_define_method(rb_cString, "to_sym", rb_str_intern, 0); /* in symbol.c */
(2-2/3)