Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Concatenates each object in objects to self and returns self:
s = 'foo'
s.concat('bar', 'baz') # => "foobarbaz"
s                      # => "foobarbaz"
For each given object object that is an Integer, the value is considered a codepoint and converted to a character before concatenation:
s = 'foo'
s.concat(32, 'bar', 32, 'baz') # => "foo bar baz"
Related: String#<<, which takes a single argument.
               static VALUE
rb_str_concat_multi(int argc, VALUE *argv, VALUE 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;

Was this page useful?