phluid61 (Matthew Kerwin) wrote:
1 [...] I would expect that a new word-based name for the dangerous operation would end with "!".
That contradicts Array#append
/ Array#prepend
. And since String#prepend
also modifies the receiver, I would expect String#append
to work in a similar way.
(Off topic but IMO, String#concat
is the one that should return a new string, just like the documentation for String#+
says: "Concatenation—Returns a new String containing other_str concatenated to str." But it's probably a bit late to fix that.)
2 [...] A method named to look like prepend, but that behaves like concat, is confusing.
Good point. I'm fine with string-only arguments. append
would simply invoke rb_str_append
then (is that a coincidence?).
3 [...] this alias would introduce confusion about which method (concat vs. append) has what arity.
It should of course work (arity-wise) like Array#append
, i.e. accept multiple argument. I should have said "concat", not "<<" in the question's title, or better yet not call it an alias in the first place.
To avoid any further confusion: I'm proposing a new method String#append
with the following signature:
append(other_str1, other_str2,...) → str¶
Append—Append the given strings to str.
a = "hello "
a.append("world", "!") #=> "hello world!"
a #=> "hello world!"
See also #concat.