Project

General

Profile

Feature #12333 ยป multi_concat_prepend.patch

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

View differences:

array.c
3620 3620

  
3621 3621
/*
3622 3622
 *  call-seq:
3623
 *     ary.concat(other_ary)   -> ary
3623
 *     ary.concat(other_ary1, other_ary2,...)   -> ary
3624 3624
 *
3625
 *  Appends the elements of +other_ary+ to +self+.
3625
 *  Appends the elements of +other_ary+s to +self+.
3626 3626
 *
3627 3627
 *     [ "a", "b" ].concat( ["c", "d"] ) #=> [ "a", "b", "c", "d" ]
3628
 *     [ "a" ].concat( ["b"], ["c", "d"] ) #=> [ "a", "b", "c", "d" ]
3629
 *     [ "a" ].concat #=> [ "a" ]
3630
 *
3628 3631
 *     a = [ 1, 2, 3 ]
3629 3632
 *     a.concat( [ 4, 5 ] )
3630 3633
 *     a                                 #=> [ 1, 2, 3, 4, 5 ]
3631 3634
 *
3635
 *     a = [ 1, 2 ]
3636
 *     a.concat(a, a)                    #=> [1, 2, 1, 2, 1, 2]
3637
 *
3632 3638
 *  See also Array#+.
3633 3639
 */
3634 3640

  
......
3643 3649
    return x;
3644 3650
}
3645 3651

  
3652
static VALUE
3653
rb_ary_concat_m(int argc, VALUE *argv, VALUE ary)
3654
{
3655
	for (int i = 0; i < argc; i++)
3656
		rb_ary_concat(ary, argv[i]);
3657

  
3658
	return ary;
3659
}
3660

  
3646 3661

  
3647 3662
/*
3648 3663
 *  call-seq:
......
5810 5825
    rb_define_method(rb_cArray, "fetch", rb_ary_fetch, -1);
5811 5826
    rb_define_method(rb_cArray, "first", rb_ary_first, -1);
5812 5827
    rb_define_method(rb_cArray, "last", rb_ary_last, -1);
5813
    rb_define_method(rb_cArray, "concat", rb_ary_concat, 1);
5828
    rb_define_method(rb_cArray, "concat", rb_ary_concat_m, -1);
5814 5829
    rb_define_method(rb_cArray, "<<", rb_ary_push, 1);
5815 5830
    rb_define_method(rb_cArray, "push", rb_ary_push_m, -1);
5816 5831
    rb_define_method(rb_cArray, "pop", rb_ary_pop_m, -1);
string.c
2766 2766
    return str1;
2767 2767
}
2768 2768

  
2769
static VALUE
2770
rb_str_concat_m(int argc, VALUE *argv, VALUE ary)
2771
{
2772
	for (int i = 0; i < argc; i++)
2773
		rb_str_concat(ary, argv[i]);
2774

  
2775
	return ary;
2776
}
2777

  
2769 2778
/*
2770 2779
 *  call-seq:
2771 2780
 *     str.prepend(other_str)  -> str
......
2786 2795
    return str;
2787 2796
}
2788 2797

  
2798
static VALUE
2799
rb_str_prepend_m(int argc, VALUE *argv, VALUE ary)
2800
{
2801
	for (int i = argc-1; i >= 0; i--)
2802
		rb_str_prepend(ary, argv[i]);
2803

  
2804
	return ary;
2805
}
2806

  
2789 2807
st_index_t
2790 2808
rb_str_hash(VALUE str)
2791 2809
{
......
9681 9699
    rb_define_method(rb_cString, "codepoints", rb_str_codepoints, 0);
9682 9700
    rb_define_method(rb_cString, "reverse", rb_str_reverse, 0);
9683 9701
    rb_define_method(rb_cString, "reverse!", rb_str_reverse_bang, 0);
9684
    rb_define_method(rb_cString, "concat", rb_str_concat, 1);
9702
    rb_define_method(rb_cString, "concat", rb_str_concat_m, -1);
9685 9703
    rb_define_method(rb_cString, "<<", rb_str_concat, 1);
9686
    rb_define_method(rb_cString, "prepend", rb_str_prepend, 1);
9704
    rb_define_method(rb_cString, "prepend", rb_str_prepend_m, -1);
9687 9705
    rb_define_method(rb_cString, "crypt", rb_str_crypt, 1);
9688 9706
    rb_define_method(rb_cString, "intern", rb_str_intern, 0); /* in symbol.c */
9689 9707
    rb_define_method(rb_cString, "to_sym", rb_str_intern, 0); /* in symbol.c */