Method: String#concat
- Defined in:
- string.c
#concat(*objects) ⇒ String
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.
3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 |
# File 'string.c', line 3731 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; } |