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
Post a Comment