ruby - Split string and append to array -


i split string , append split result 2 separate arrays simultaneously. there way this? example:

mystrings = ['abc:def', 'ghi:jkl', 'mno:pqr'] first = [] second = [] mystrings.each |string|   first, second << string.split(':') end 

this doesn't work. didn't know if there syntactical ruby way perform split , appending simultaneously.

mystrings = ['abc:def', 'ghi:jkl', 'mno:pqr'] first, second = mystrings.map{|str| str.split(":")}.transpose 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -