I'm using Ruby 2.4. I'm trying to split elements in an array. What I would like is to form to equivalent arrays with the results of my split. I would like the first part of the split to be the first array and the second part of teh split to be the second array. So I have
data_col = ["mm a", "nn b", "nn a"]
arr1, arr2 = data_col.map do |x|
if x
a, b, c = x.partition(/(^|[[:space:]]+)[ab]$/i)
[b.strip, a + c]
else
[nil, nil]
end
end.transpose
#=> [["a", "b", "a"], ["mm", "nn", "nn"]]
The problem is, the split is working, but the arrays are getting reversed. I want the ["mm", "nn", "nn"]
to be the first element in the array. How do I rewrite things so that the arrays are returned properly -- that is, the first part of the split is in the first array and the second part of the split is in the second array?