Method: String#concat

Defined in:
string.c

#concat(obj1, obj2, ...) ⇒ String

Concatenates the given object(s) to str. If an object is an Integer, it is considered a codepoint and converted to a character before concatenation.

concat can take multiple arguments, and all the arguments are concatenated in order.

a = "hello "
a.concat("world", 33)      #=> "hello world!"
a                          #=> "hello world!"

b = "sn"
b.concat("_", b, "_", b)   #=> "sn_sn_sn"

See also String#<<, which takes a single argument.

Returns:



3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
# File 'string.c', line 3028

static VALUE
rb_str_concat_multi(int argc, VALUE *argv, VALUE str)
{
    str_modifiable(str);

    if (argc == 1) {
	return rb_str_concat(str, argv[0]);
    }
    else if (argc > 1) {
	int i;
	VALUE arg_str = rb_str_tmp_new(0);
	rb_enc_copy(arg_str, str);
	for (i = 0; i < argc; i++) {
	    rb_str_concat(arg_str, argv[i]);
	}
	rb_str_buf_append(str, arg_str);
    }

    return str;
}