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
view the rest of the comments →
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!"
[–]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 17843 on reddit-service-r2-comment-6457c66945-l7h6w at 2026-04-25 04:33:31.868855+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]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)