Skip to content

Instantly share code, notes, and snippets.

@theHamdiz
Created February 19, 2016 23:37
Show Gist options
  • Select an option

  • Save theHamdiz/1276ab3451dbf5f5d0f1 to your computer and use it in GitHub Desktop.

Select an option

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!
# 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