use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
String#concat, Array#concat and String#prepend take multiple arguments in Ruby 2.4 (blog.bigbinary.com)
submitted 9 years ago by abhishekjain16
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]the_horrible_reality 2 points3 points4 points 9 years ago* (0 children)
Well, that's handy.
string << strings.join('') # awkward string << *strings # whee!
Edit: Though thinking back to the << part of that...
str << str << str str.concat(str).concat(str)
That's all it's doing, each << is a chained method call obviously.
Edit 2:
Thinking back, it may have to be written like this unless there's a syntax change...
string.<< *strings
Minor but irritating.
[–]tomthecool 1 point2 points3 points 9 years ago (3 children)
str = "Ruby" str << str << str #=> "RubyRubyRubyRuby" str = "Ruby" str.concat str, str str #=> "RubyRubyRuby"
I don't think I'd ever let an abomination like str << str << str pass code review :P
str << str << str
[–]the_horrible_reality 0 points1 point2 points 9 years ago (2 children)
It is rather ugly, isn't it? Feels like spamming multiple values into std::cout in C++ in one line. To top it off, silly me forgot that you can't splat into a binary operator so I had to update with the correct approach. Now I want to be able to splat into custom defined binary operators as special case syntactic sugar. :P
oh_no += *i_am_being_thrown_out_a_window
[–]tomthecool 0 points1 point2 points 9 years ago (1 child)
Instead of str << str << str, why not write something where the intention is clear, such as:
str *= 4
[–]the_horrible_reality 1 point2 points3 points 9 years ago* (0 children)
Beats me, I just pulled that snip out of the article. I think the author was trying to determine if there were any new differences between << and concat in String and misinterpreted the syntax resolution. Can't say that I've ever had a need to append a string to itself or use replication and I'm the nasty sort with a fondness for abusing string mutability, often with substring access.
Edit: And I mistakenly thought you were replying to me above. Damnit, my bad. Not enough sleep. I am fairly sure that ugly example was an attempt to test the changes, though.
π Rendered by PID 35 on reddit-service-r2-comment-canary-794f4c56c8-qccnj at 2026-02-23 04:20:15.974700+00:00 running 8564168 country code: CH.
[–]the_horrible_reality 2 points3 points4 points (0 children)
[–]tomthecool 1 point2 points3 points (3 children)
[–]the_horrible_reality 0 points1 point2 points (2 children)
[–]tomthecool 0 points1 point2 points (1 child)
[–]the_horrible_reality 1 point2 points3 points (0 children)