Created
February 19, 2016 23:37
-
-
Save theHamdiz/1276ab3451dbf5f5d0f1 to your computer and use it in GitHub Desktop.
Cool array join trick using Ruby. You would've never guessed it was that easy to accomplish!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # facebook.com/ruby.dose | |
| # This is one of the coolest join tricks ruby can provide you... | |
| # creating an array of string literals, multiplying this array by another | |
| # string literal will actually cause joining this array together using | |
| # the latter string literal | |
| puts %w|Mohamad Abdullah Abdulmotaleb| * ' Ibn ' | |
| puts %w{Ahmad Hamdi Saad Emara} * ' Ibn ' | |
| # Give it a spin, and have some fun playing with it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment